AddThis

Wednesday, August 17, 2011

Spring and JBoss Integration

Oh Spring and JBoss, can't you two just play nice? What is this "java.util.zip.ZipException" nonsense? Well turns out that JBoss attempts to standardize all of its resource access, regardless of where the actual resource is located, be it a jar or some directory. This is accomplished by abstracting away this access using a VFS, or Virtual File System.
This is where Spring and JBoss collide. When Spring performs its resource scanning, it assumes direct access from either a jar or directory, and consequently uses corresponding URLs, which clashes with VFS. JBoss has a fix for this however and replaces Spring's ClassPathXmlApplicationContext with its own VFSClassPathXmlApplicationContext.

All you have to do is include the snowdrop-vfs.jar and one or both of the following:

If you load spring using the ContextLoaderListener say for services, then you would do the following:


<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath*:spring-contexts/*.xml</param-value>
</context-param>
<context-param>
  <param-name>contextClass</param-name>
  <param-value>org.jboss.spring.vfs.context.VFSXmlWebApplicationContext</param-value>
</context-param>
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


If you also have a servlet for web requests, then you would do the following:

<servlet>
  <servlet-name>spring-mvc-servlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-config.xml</param-value>
  </init-param>
  <init-param>
    <param-name>contextClass</param-name>
    <param-value>org.jboss.spring.vfs.context.VFSXmlWebApplicationContext</param-value>
  </init-param>
</servlet>


*JBoss EAP 5.1
*Spring 2.2
*snowdrop-vfs.zip (version 1.0)

No comments: