4.4. The Spring Deployer

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.

4.4.1. JBoss + Spring + EJB 3.0 Integration

Snowdrop contains a JBoss deployer that supports Spring packaging in Red Hat JBoss Enterprise Application Platform. This means it is possible to create JAR archives with a META-INF/jboss-spring.xml file to have the Spring bean factories deploy automatically.
EJB 3.0 integration is also supported. Spring beans created in such archive deployments can be injected directly into an EJB by using the @Spring annotation.

4.4.2. Installation on Red Hat JBoss Enterprise Application Platform 6

4.4.2.1. Manual Installation of Snowdrop

Warning

  • Spring 2.5 is deprecated from the release of JBoss Web Framework Kit 2.4.0. This means that Spring 2.5 will continue to be tested and supported in JBoss Web Framework Kit 2.x. Note that subsequent Spring 2 releases will not be tested or supported in JBoss Web Framework Kit.
  • Spring 3.0.x and 3.1.x are deprecated from the release of JBoss Web Framework Kit 2.5.0. This means that Spring 3.0.x and 3.1.x will continue to be tested and supported in JBoss Web Framework Kit 2.x. Note that Spring 3.2.x and later are not deprecated and continue to be tested and supported in JBoss Web Framework Kit.
To install the Snowdrop Deployment subsystem, navigate to the snowdrop-subsystem-as7 directory in the JBoss Web Framework Kit distribution. Create the subsystem and Spring modules in JBoss Enterprise Application Platform by copying the contents of the module-deployer directory and one of the module-spring-2.5/, module-spring-3/, module-spring-3.1/, module-spring-3.2/, module-spring-4.0/ or module-spring-4.1/ directories in the $JBOSS_HOME/modules/system/add-ons/snowdrop directory of your JBoss Enterprise Application Platform installation.
The above step creates two modules inside JBoss Enterprise Application Platform:
org.jboss.snowdrop:main
The module that contains the JBoss Enterprise Application Platform subsystem.
org.springframework.spring:snowdrop
A module that contains the Spring JARs required by Snowdrop. It can contain Spring 2.5, Spring 3, Spring 3.1, Spring 3.2, Spring 4.0 or Spring 4.1 JARs, depending on the previously chosen version. Users may add other JARs to the module, case in which they need to adjust the module.xml file accordingly. It is a dependency of org.jboss.snowdrop:main
The Web Framework Kit distribution does not contain Spring archives, so you will need to install them separately. Copy one of the files of corresponding versions from Maven Central.

Spring 2.5.6.SEC03

  • aspectjrt.jar
  • aspectjweaver.jar
  • aopalliance.jar
  • spring-aop.jar
  • spring-beans.jar
  • spring-core.jar
  • spring-context.jar
  • spring-context-support.jar
  • spring-web.jar

Spring 3.0.7.RELEASE and Spring 3.1.4.RELEASE

  • aspectjrt.jar
  • aspectjweaver.jar
  • aopalliance.jar
  • spring-aop.jar
  • spring-asm.jar
  • spring-beans.jar
  • spring-core.jar
  • spring-expression.jar
  • spring-context.jar
  • spring-context-support.jar
  • spring-web.jar

3.2.13.RELEASE, 4.0.9.RELEASE, and 4.1.4.RELEASE

  • aspectjrt.jar
  • aspectjweaver.jar
  • aopalliance.jar
  • spring-aop.jar
  • spring-beans.jar
  • spring-core.jar
  • spring-expression.jar
  • spring-context.jar
  • spring-context-support.jar
  • spring-web.jar
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.

4.4.2.2. Automatic Installation of Snowdrop

For easy installation of Snowdrop module, use the Snowdrop installer. The installer copies Snowdrop and Spring jars to their appropriate location within ${JBOSS_HOME}/modules directory. The installer also creates new $JBOSS_HOME/standalone/configuration/standalone-snowdrop.xml file based on $JBOSS_HOME/standalone/configuration/standalone.xml to register the snowdrop extension and subsystem. You can run JBoss Enterprise Application Platform with this new configuration using $JBOSS_HOME/bin/standalone.sh --server-config=standalone-snowdrop.xml.
To install Snowdrop using the installer, on the command line, navigate to the snowdrop-module-installer directory in the Web Framework Kit distribution and execute the following command:
mvn package -DJBOSS_HOME=/path/to/jboss_home
By default, the installer installs Snowdrop 3.1.1.Final-redhat-1 and Spring 4.1.4.RELEASE. To install a different version, execute the following command:
mvn package -P${desired-spring-version} -DJBOSS_HOME=/path/to/jboss_home -Dversion.snowdrop=${desired-snowdrop-version}
For details of the supported configurations click here.

4.4.3. Defining the JNDI name

You can specify the JNDI name explicitly by putting it in the description element of the Spring XML.
<beans>
  <description>BeanFactory=(MyApp)</description>
  ...
  <bean id="springBean" class="example.SpringBean"/>
</beans>
MyApp will be used as the JNDI name in this example.

4.4.4. Parent Bean factories

Sometimes the deployed Spring bean factory must be able to reference beans deployed in another Spring deployment. This can be done by declaring a parent bean factory in the description element in the Spring XML, as follows:
<beans>
<description>BeanFactory=(AnotherApp) ParentBeanFactory=(MyApp)</description>
...
</beans>

4.4.5. Injection into EJBs

Once an ApplicationContext has been successfully bootstrapped, the Spring beans defined in it can be used for injection into EJBs. To do this, the EJBs must be intercepted with the SpringLifecycleInterceptor, as in the following example:
@Stateless
@Interceptors(SpringLifecycleInterceptor.class)
public class InjectedEjbImpl implements InjectedEjb
{
 @Spring(bean = "springBean", jndiName = "MyApp")
 private SpringBean springBean;

 /* rest of the class definition ommitted */
}
In this example, the EJB InjectedEjbImpl will be injected with the bean named springBean, which is defined in the ApplicationContext.