SeamFramework.orgCommunity Documentation

Seam Spring


If you are using Maven as your build tool, you can add the following single dependency to your pom.xml file to include the Seam Spring module.


<dependency>
   <groupId>org.jboss.seam.spring</groupId>
   <artifactId>seam-spring-core</artifactId>
   <version>${seam.spring.version}</version>
</dependency>

Tip

Substitute the expression ${seam.spring.version} with the most recent or appropriate version of Seam Spring.

The functionality of the Seam Spring module is provided by two sets of components:

  • A CDI portable extension for accessing Spring application contexts and managing Spring beans;

  • A FactoryBean and corresponding namespace for accessing BeanManagers and importing CDI beans into Spring.

The Seam Spring module uses the resource producer pattern for accessing Spring contexts and beans from within CDI. The Spring extension is responsible for producing the actual instances. This mechanism allows the Spring beans to participate in regular CDI injection and the injection targets to be agnostic of the provenience of the injected references, enforcing true separation of concerns. Through this mechanisms Spring contexts can be injected as Spring beans too, if necessary.

The resource producer pattern is used for:

The registration of Spring application contexts as CDI beans is a prerequisite for accessing the Spring beans that are created by them.

The Seam Spring module can access two types of contexts:

CDI applications can install Spring contexts as CDI beans by defining producer fields with the following general pattern:

@Produces

@SpringContext
@<Context-Type>
ApplicationContext context;

This will create a CDI bean of the ApplicationContext type. The nature of the context (bootstrapped by the extension, or looked up elsewhere) is controlled by a specific annotation. The supported annotations are detailed in the following subsections.

The Seam Spring module also supports the registration of CDI beans as Spring beans as well. Once CDI beans are imported into a Spring ApplicationContext, they can be injected as regular Spring beans, either via XML or by annotations.

This can be done by using the dedicated CDI namespace, which can be defined as in the following example:


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

   <!-- bean definitions -->

</beans>