Coming back to setting up Spring, Spring WebMVC and Apache CXF

After some while I got back to work in the web context with latest versions of SpringFramework, Apache CXF and Servlets. So I had many thoughts about setting up projects with these libraries. The main application services should be used by web services running in Apache CXF and a normal web application running with Spring WebMVC.

There are a lot of guides in the web describing the setup and some good books about Spring WebMVC. The best structure I came up with was to have three different contexts. One with the main application services as the web applications root context (application-context.xml). The second one for the controllers used by Spring WebMVC (DispatcherServlet-context.xml) and the third one containing the web services exposed by Apache CXF (CXFServlet-context.xml).


The contexts DispatcherServlet-context.xml and CXFServlet-context.xml are loaded by the Spring WebMVC’s DispatcherServlet and Apache CXF’s CXFServlet having the main Spring Context application-context.xml as parent. This helps separating the business layer in the main application-context from the frontend-layers in the Spring WebMVC context and Apache CXF context. Because the services in the business-layer can’t access the services in the Spring WebMVC and Apache CXF context. Also the services in the different frontend-layers aren’t possible to call each other across different contexts. The setup is mainly in the file web.xml where the CXFServlet gets a special init-parameter config-location with the value /WEB-INF/CXFServlet-context.xml.


Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )


Verbinde mit %s