JBoss.orgCommunity Documentation

Chapter 2. Component usage

2.1. The VFS-supporting application contexts
2.2. Load-time weaving
2.3. The Spring Deployer
2.3.1. JBoss + Spring + EJB 3.0 Integration
2.3.2. Installation
2.3.3. Spring deployments
2.3.4. Deployment
2.3.5. Defining the JNDI name
2.3.6. Parent Bean factories
2.3.7. Injection into EJBs

This chapter details how to use the individual components of the package.

For using this functionality, the snowdrop-vfs.jar file needs to be added to the application.

This library supports resource scanning in JBoss' Virtual File System. When doing resource scanning, the Spring framework assumes that the resources are either coming from a directory or a packaged jar, and treats the URLs encountered in the process of scanning resources accordingly. This assumption does not hold in JBoss' Virtual File System.

The solution to this problem is in implementing a different underlying resource resolution mechanism, namely in amending the functionality of the PathMatchingResourcePatternResolver. From the user's perspective, using this different resolution mechanism is done through using one of the two ApplicationContext implementations provided by this library, which are:

In many cases, the VFSClassPathXmlApplicationContext would be instantiated on its own, using something like:

ApplicationContext context = 
  new VFSClassPathXmlApplicationContext("classpath:/context-definition-file.xml");

The XmlWebApplicationContext is not instantiated directly, though, but bootstrapped by either the ContextLoaderListener, or the DispatcherServlet. In this case, the class to be used for bootstrapping needs to be used to trigger an instantiation of the VFS-enabled context.

For changing the type of application context created by the ContextLoaderListener, use the contextClass parameter, as shown in the sample below:

For changing the type of application context created by the DispatcherServlet, use the contextClass parameter again, but this time on the DispatcherServlet definition (emphasized portion again):

<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>

Both configurations can be seen at work in the web-scanning sample.

In order to perform load-time weaving for the application classes in Spring (either for using load-time support for AspectJ or for JPA support), the Spring framework needs to install its own transformers in the classloader. In certain cases (like for JBoss 5.x), a classloader-specific LoadTimeWeaver is necessary. The functionalities described in this chapter are included in the snowdrop-weaving.jar file.

To that effect, if a load-time weaver needs to be defined in the www Spring application context, use the JBoss5LoadTimeWeaver class, as follows:

<context:load-time-weaver weaver-class="org.jboss.instrument.classloading.JBoss5LoadTimeWeaver"/>

The role of the Spring Deployer is to allow the bootstrapping of a Spring application context, binding it in JNDI and using it for providing Spring-configured business object instances.