2013-01-13 50 views
0

我最近試圖使用Spring的項目(3.1.1.RELEASE)將Hibernate Session管理到Seam(2.3.0.Final)中。如何在Seam中使用Spring管理的Hibernate會話?

在JBoss Seam他們解釋的文檔How to use Seam Managed Hibernate Session in Spring。但是我們的要求是比文件反轉。

我得到了另一個解決方案Using Spring PlatformTransactionManagement但我的要求是在Seam中使用Spring Managed Hibernate Session。我不想使用Seam管理Hibernate Session/Hibernate Entity Manager/Transaction。只想使用Seam管理依賴注入通過seam @In而不是Spring @Autowire將Spring bean注入到Seam管理bean中。

如果有人面臨這種​​類型的挑戰,請幫助的配置Seam components.xml &春applicationContext.xml或提供給我指導線,以克服這一點。

回答

0

首先配置applicationContext.xml因爲通常你配置:

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <!-- hibernate Properties Here -->      
</bean> 
<bean id="transactionManager" 
    class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 
<tx:annotation-driven/> 

然後配置components.xml如下:

<core:init debug="true" transaction-management-enabled="true" /> 
<spring:context-loader config-locations="classpath*:/META-INF/spring/applicationContext.xml"/> 
<core:manager concurrent-request-timeout="500" conversation-timeout="120000" conversation-id-parameter="cid" parent-conversation-id-parameter="pid" /> 
<persistence:managed-hibernate-session name="hibernateSession" auto-create="true" session-factory="#{sessionFactory}"/> 
<spring:spring-transaction platform-transaction-manager="#{transactionManager}"/> 

它很容易與Seam互動春季(3.1.1.RELEASE)(2.3 .0.Final),但永遠不要忘記配置web.xml接縫。

<listener> 
    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class> 
</listener> 

<listener> 
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
</listener> 

<servlet> 
    <servlet-name>Seam Resource Servlet</servlet-name> 
    <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Seam Resource Servlet</servlet-name> 
    <url-pattern>/resource/*</url-pattern> 
</servlet-mapping> 

<filter> 
    <filter-name>Seam Filter</filter-name> 
    <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>Seam Filter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern> 
</servlet-mapping> 

<login-config> 
    <auth-method>BASIC</auth-method> 
</login-config> 

<session-config> 
    <session-timeout>10</session-timeout> 
</session-config> 

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
</welcome-file-list> 

找到Facelets您應該faces-config.xml

<application> 
    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver> 
</application> 

最好加變量解析器下載Seam-2.3.0.Final。 Uzip它,裏面examples\spring\文件夾,你會得到你想要的配置