이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 26. Spring Framework integration


The Spring Framework is part of the Seam inversion-of-control (IoC) module. It allows easy migration of Spring-based projects to Seam, and benefits Spring applications with Seam features, such as conversations and a more sophisticated persistence context management.

Note

The Spring integration code is included in the jboss-seam-ioc library. This library is a required dependency for all Seam-Spring integration techniques covered in this chapter.
Seam's support for Spring gives you:
  • Seam component injection into Spring beans,
  • Spring bean injection into Seam components,
  • Spring bean to Seam component transformation,
  • the ability to place Spring beans in any Seam context,
  • the ability to start a spring WebApplicationContext with a Seam component,
  • support for using Spring PlatformTransactionManagement with your Seam-based applications,
  • support for using a Seam-managed replacement for Spring's OpenEntityManagerInViewFilter and OpenSessionInViewFilter, and
  • support for backing @Asynchronous calls with Spring TaskExecutors.

26.1. Injecting Seam components into Spring beans

Inject Seam component instances into Spring beans with the <seam:instance/> namespace handler. To enable the Seam namespace handler, the Seam namespace must first be added to the Spring beans definition file:
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:seam="http://jboss.com/products/seam/spring-seam"
       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-2.0.xsd
          http://jboss.com/products/seam/spring-seam
          http://jboss.com/products/seam/spring-seam-2.2.xsd">
Copy to Clipboard Toggle word wrap
Any Seam component can now be injected into any Spring bean, like so:
<bean id="someSpringBean" class="SomeSpringBeanClass" scope="prototype">
  <property name="someProperty">
    <seam:instance name="someComponent"/>
  </property>
</bean>
Copy to Clipboard Toggle word wrap
You can use an EL expression instead of a component name:
<bean id="someSpringBean" class="SomeSpringBeanClass" scope="prototype">
  <property name="someProperty">
    <seam:instance name="#{someExpression}"/>
  </property>
</bean>
Copy to Clipboard Toggle word wrap
You can inject a Seam component instance into a Spring bean by using a Spring bean ID, like so:
<seam:instance name="someComponent" id="someSeamComponentInstance"/>

<bean id="someSpringBean" class="SomeSpringBeanClass" scope="prototype">
  <property name="someProperty" ref="someSeamComponentInstance">
</bean>

Copy to Clipboard Toggle word wrap
However, Spring, unlike Seam, was not designed to support a stateful component model with multiple contexts. Spring injection does not occur at method invocation time, but when the Spring bean is instantiated.
The instance available when the bean is instantiated will be used for the entire life of the bean. Say you inject a Seam conversation-scoped component instance directly into a singleton Spring bean — that singleton will hold a reference to the same instance long after the conversation is over. This is called scope impedance.
Seam bijection maintains scope impedance naturally as an invocation flows through the system. In Spring, we must inject a proxy of the Seam component, and resolve the reference when the proxy is invoked.
The <seam:instance/> tag lets us automatically proxy the Seam component.
<seam:instance id="seamManagedEM" 
               name="someManagedEMComponent" 
               proxy="true"/>

<bean id="someSpringBean" class="SomeSpringBeanClass">
  <property name="entityManager" ref="seamManagedEM">
</bean>
Copy to Clipboard Toggle word wrap
Here, we see one example of using a Seam-managed persistence context from a Spring bean. See the section on Section 26.6, “Using a Seam-Managed Persistence Context in Spring” for a more robust way to use Seam-managed persistence contexts as a replacement for the Spring OpenEntityManagerInView filter.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat