< Previous | Front page | Next >
Skip to end of metadata
Go to start of metadata

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.

JBoss + Spring + EJB 3.0 Integration

Snowdrop contains a JBoss deployer that supports Spring packaging in JBoss AS. This means that it is possible to create JAR archives with a META-INF/jboss-spring.xml file to have your Spring bean factories deploy automatically.

EJB 3.0 integration is also supported. You can deploy Spring archives and inject beans created in these deployments directly into an EJB by using the @Spring annotation.

Installation

Installation on JBoss AS 5 and JBoss AS 6

To install the Snowdrop JBoss deployer, unzip the jboss-spring-deployer.zip in the $JBOSS_HOME/server/$PROFILE/deployers directory of your JBoss Application Server installation.

Installation on JBoss AS 7

The installation of the JBoss AS7 consists of two steps:

Step 1. Install the subsystem modules

To install the Snowdrop Deployment subsystem, unzip the subsystem-as7-distribution.zip and copy the contents of the deployer subdirectory into the $JBOSS_HOME/modules directory of your JBoss Application Server (the result being that the org folder is copied immediately underneath modules). The distribution also contains a module-spring-2.5 directory. If you wish to use the deployer with Spring 2.5, remove the $JBOSS_HOME/modules/org/springframework/spring/snowdrop folder and use the content of this directory to replace it.

Step 2. Activate the subsystem extension

The final step in the installation is to change $JBOSS_HOME/standalone/configuration/standalone.xml by including:

inside the <extensions> element, as well as including:

inside the <profile> element.

The final result will look like this:

Spring deployments

You can create Spring deployments that work similarly to JARs, EARs, and WARs with the JBoss Spring deployer. Spring JARs are created with the following structure:

my-app.spring/
  org/
    acme/
      MyBean.class
      MyBean2.class
  META-INF/
    jboss-spring.xml

my-app.spring is a JAR that contains classes. A jboss-spring.xml file exists in the META-INF directory of the JAR. By default, the JBoss Spring deployer registers the bean factory defined in jboss-spring.xml into JNDI in a non-serialized form. The default JNDI name is the short name of the deployment file — in this case, my-app.

You can also place JAR libraries under $JBOSS_HOME/server/$PROFILE/lib and add an XML file of the form <name>-spring.xml, for example, my-app-spring.xml, into the deploy directory of your JBoss Enterprise Application Platform or JBoss Enterprise Web Platform installation. The default JNDI name will be the short name of the XML file; in this case, my-app.

Deployment

Once you have created a .spring or a -spring.xml file, copy it into the deploy directory of your JBoss AS installation to deploy it into the JBoss runtime. You can also embed these deployments in an EAR, EJB-SAR, SAR, and so on, since JBoss AS supports nested archives.

Defining the JNDI name

You can specify the JNDI name explicitly by putting it in the description element of the Spring XML.

MyApp will be used as the JNDI name in this example.

Parent Bean factories

Sometimes you want your deployed Spring bean factory to be able to reference beans deployed in another Spring deployment. You can do this by declaring a parent bean factory in the description element in the Spring XML, like so:

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:

In this example, the EJB InjectedEjbImpl will be injected with the bean named springBean, which is defined in the ApplicationContext.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.