Friday, February 07, 2014

Example: Spring-MVC Spring-JDBC Spring-WS CastorMarshaller and jQuery

This is a web application, which front end is all about jQuery, back end is Spring-MVC to provide JSON web services, and Spring-JDBC to access a relational database, and Spring-WS to access a remote SOAP web services, and CastorMarshaller to convert between Java POJO and SOAP XML.

It starts with a Maven pom.xml.



The access to the relational database and the access to the remote SOAP web services are totally parallel so I don't want any cross point between them. I set up two source folders to hold them respectively but point both output folder to src/main/webapp/WEB-INF/classes.

Now it comes to the web.xml.



As you can see, I use rest-context.xml to define the rest servlet.



This rest xml is rather simple. It simply scans two controllers packages for @Controller. But I have defined in the web.xml to delegate all app1 related spring beans to app1Context.xml and app2 to app2Context.xml which sit right at their source folders respectively.

The app1Context.xml is for accessing the relational database.



You will be wondering about where is the java:/myApp1DS. This comes to the JBoss JNDI datasource configuration. Create a xml file called myApp1-ds.xml.



You will of course first enable that JDBC driver on the JBoss, but it should be an easy walk for any JBoss guy. Then deploy the myApp1-ds.xml to the server/default/deploy folder. Remember this file name has to be -ds.xml. It rather makes JBoss look like a toy.

No comments: