JBoss.orgCommunity Documentation

Chapter 3. Component usage

3.1. VFS-enabled Application Contexts
3.2. The JBoss custom namespace
3.2.1. Accessing the default JBoss MBean Server
3.2.2. JCA/JMS support beans
3.3. Load-time weaving
3.4. The Spring Deployer
3.4.1. JBoss + Spring + EJB 3.0 Integration
3.4.2. Spring Deployer Installation
3.4.3. Spring deployments
3.4.4. Deployment
3.4.5. Defining the JNDI name
3.4.6. Parent Bean factories
3.4.7. Injection into EJBs

This chapter details how to use each of the components included in Snowdrop.

The snowdrop-vfs.jar library supports resource scanning in the JBoss Virtual File System (VFS). It must be included in Spring-based applications that use classpath and resource scanning.

When the Spring framework performs resource scanning, it assumes that resources are either from a directory or a packaged JAR, and treats any URLs it encounters accordingly.

This assumption is not correct for the JBoss VFS, so Snowdrop provides a different underlying resource resolution mechanism by amending the functionality of the PathMatchingResourcePatternResolver.

This is done by using one of two ApplicationContext implementations provided by snowdrop-vfs.jar:

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

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

The XmlWebApplicationContext is not instantiated directly. Instead, it is bootstrapped by either the ContextLoaderListener or the DispatcherServlet. Both classes have configuration options that allow users to replace the default application context type with a custom application context type.

To change the type of application context created by the ContextLoaderListener, add the contextClass parameter as shown in the following example code:

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

To change the type of application context created by the DispatcherServlet, use the same contextClass parameter on the DispatcherServlet definition as shown:

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

Starting with version 1.2, Snowdrop includes a custom Spring namespace for JBoss AS. The goals of this custom namespace is to simplify the development of Spring applications that run on JBoss, by reducing the amount of proprietary code and improving portability.

The amount of proprietary code is reduced because of replacing bean definitions that include references to specific JBoss classes with namespace-based constructs. All the knowledge about the proprietary classes is encapsulated in the namespace handlers.

The applications are more portable because certain proprietary classes may change when upgrading to a different version of the application server. In such cases, the runtime will be detected automatically by Snowdrop which will set up beans using the classes that are appropriate for that specific runtime.

The custom namespace can be set up as follows:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jboss="http://www.jboss.org/schema/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.jboss.org/schema/snowdrop http://www.jboss.org/schema/snowdrop/snowdrop.xsd">

Load-time weaving support is provided by the snowdrop-weaving.jar library.

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. For JBoss Enterprise Application Platform, JBoss Enterprise Web Platform and JBoss Enterprise Web Server, a classloader-specific LoadTimeWeaver is necessary.

Define the JBossLoadTimeWeaver in the Spring application context as shown here:

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

The Spring deployer allows you to bootstrap a Spring application context, bind it in JNDI, and use it to provide Spring-configured business object instances.

To install the Snowdrop Deployment subsystem, unzip the jboss-spring-subsystem-as7.zip file. Create the subsystem and Spring modules in JBoss AS7 by copying the contents of the module-deployer folder and one of the module-spring-2.5 or spring-3 folders in the $JBOSS_HOME/modules directory of your JBoss Application Server installation.

The above step will create two modules inside JBoss AS7:

If you are using the distribution without dependencies, or you wish to create your own version of the Spring module, then create a $JBOSS_HOME/modules/org/springframework/spring/main directory and copy one of the two module.xml files (from either the module-spring-2.5 or the module-spring-3 directory of the distribution and copy one of the following sets of files from the corresponding Spring distribution (either Spring 2.5.6.SEC03 or Spring 3.0.6.RELEASE).

For Spring 2.5:

For Spring 3:

The final step in the installation is to change $JBOSS_HOME/standalone/configuration/standalone.xml by including <extension module="org.jboss.snowdrop"/> inside the <extensions> element, as well as including <subsystem xmlns="urn:jboss:domain:snowdrop:1.0"/> inside the <profile> element.