10 Replies Latest reply on Oct 28, 2008 8:04 PM by Guillaume Jeudy

    legacy spring service layer

    Robert Shanahan Newbie

      I have a legacy Spring based application that has a dao/domain layer and a service layer over that. The dao/domain layer uses Spring's HibernateDaoSupport. The service layer beans are injected with daos. The service and domain components are used by a couple of Struts applications and lazy loading is managed with Spring's OpenSessionInViewFilter.


      I'm developing a Seam proof-of-concept, hoping to realize the benefits of RESTful JSF, ajax, etc., etc. and breathe new life into these applications. However, I'm at a loss with regard to configuring a persistence context for a legacy Spring dao based architecture.




        • 1. Re: legacy spring service layer
          Robert Shanahan Newbie

          Snippet from domain layer app context:
               


          <bean id="sessionFactory"
                    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init="true">
                    <property name="dataSource" ref="${datasource}"/>
                    <property name="mappingLocations">
                          <value>classpath:com/i2i/domain/*.hbm.xml</value>
                   </property>
                    <property name="hibernateProperties">
                         <props>
                              <prop key="hibernate.dialect">
                                   ${hibernate.dialect}
                              </prop>
                              <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                              <prop key="hibernate.cache.use_query_cache">false</prop>
                              <prop key="hibernate.cache.use_second_level_cache">true</prop>
                              <prop key="hibernate.cache.provider_class">
                                   org.hibernate.cache.EhCacheProvider
                              </prop>
                              <prop key="hibernate.cache.provider_configuration_file_resource_path">
                                   ehcache-hibernate.xml
                              </prop>
                              <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batchsize}</prop>
                         </props>
                    </property>
               </bean>
          
               <bean id="transactionManager"
                    class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
                    <property name="sessionFactory">
                         <ref local="sessionFactory" />
                    </property>
               </bean>
          
               <bean id="i2iDaoTarget" class="com.i2i.dao.I2iDao" lazy-init="true">
                    <property name="sessionFactory">
                         <ref local="sessionFactory" />
                    </property>
                    <property name="defaultFetchSize" value="${dao.hibernate.defaultFetchSize}"/>
               </bean>
               
               <bean id="i2iDao" parent="txProxyTemplate">
                    <property name="target">
                         <ref local="i2iDaoTarget" />
                    </property>
               </bean>
          
               <bean id="txProxyTemplate" lazy-init="true"
                    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
                    <property name="transactionManager">
                         <ref local="transactionManager" />
                    </property>
                    <property name="transactionAttributes">
                         <props>
                              <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                              <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                              <prop key="refresh">PROPAGATION_REQUIRED,readOnly</prop>
                              <prop key="merge*">PROPAGATION_REQUIRED</prop>
                              <prop key="insert*">PROPAGATION_REQUIRED</prop>
                              <prop key="update*">PROPAGATION_REQUIRED</prop>
                              <prop key="delete*">PROPAGATION_REQUIRED</prop>
                              <prop key="save*">PROPAGATION_REQUIRED</prop>
                              <prop key="create*">PROPAGATION_REQUIRES_NEW</prop>
                              <prop key="authenticate">
                                   PROPAGATION_REQUIRED,readOnly
                              </prop>
                         </props>
                    </property>
               </bean>
          
          


          Snippet from service layer app context:



               <bean id="i2iAuthenticationProvider"
                    class="com.i2i.services.security.AuthenticationProvider" lazy-init="true">
                    <property name="defaultRole">
                         <value>ROLE_ANONYMOUS</value>
                    </property>
                    <property name="i2iDao">
                         <ref bean="i2iDao" />
                    </property>
                    <property name="userCache">
                         <ref local="userCache" />
                    </property>
               </bean>



          components.xml



             <!-- how do you configure this for legacy spring dao? 
             <persistence:managed-persistence-context name="entityManager"
                                                auto-create="true" 
                                                entity-manager-factory="#{entityManagerFactory}" /> 
             -->
             
             <spring:spring-transaction platform-transaction-manager="#{transactionManager}" join-transaction="true" auto-create="true"/>
             <security:identity authenticate-method="#{authenticator.authenticate}"/>
          
          
          



          And finally, my authenticator, which fails with a LazyInitializationException, as expected, since it has no persistence context to manage its session scope.



          @Scope(EVENT)
          @Name("authenticator")
          public class Authenticator
          {
              @In Identity identity;
              @In ("#{authenticationManager}") private AuthenticationManager _authManager;
              
              public boolean authenticate()
              {
                  Authentication a = new UsernamePasswordAuthenticationToken(identity.getUsername(), identity.getPassword());
                  
                  try
                  {
                      hibernateSession.setFlushMode(FlushMode.AUTO);
                      
                      Authentication principal = _authManager.authenticate(a);
                      
                      identity.setUsername(principal.getName());
                      
                      for(GrantedAuthority g: principal.getAuthorities())
                      {
                          identity.addRole(g.getAuthority());
                      }
                  }
                  catch(AuthenticationException e)
                  {
                      return false;
                  }
                  
                  return true;
              }
          }
          


          • 3. Re: legacy spring service layer
            Robert Shanahan Newbie

            I read the article and was inspired by it to devise a configuration that requires no alterations to the legacy Spring components. Seems straightforward, however, the app fails on startup with a java.lang.IllegalStateException: No active application scope


            web.xml snippet:


               <context-param>
                  <param-name>contextConfigLocation</param-name>          
                  <param-value>/WEB-INF/applicationContext.xml</param-value>
               </context-param>
               <context-param>
                  <param-name>locatorFactorySelector</param-name>
                  <param-value>classpath:com/alas/i2i/services/beanRefFactory.xml</param-value>
               </context-param>
               <context-param>
                  <param-name>parentContextKey</param-name>
                  <param-value>i2i.services</param-value>
               </context-param>
               <context-param>
                  <param-name>webAppRootKey</param-name>
                  <param-value>i2i.root</param-value>
               </context-param>
                
               <!-- Seam -->
               <listener>
                  <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
               </listener>
                
               <listener>
                  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
               </listener>
            


            web layer applicationContext.xml:


            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
                 xmlns:util="http://www.springframework.org/schema/util" xmlns:seam="http://jboss.com/products/seam/spring-seam"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
                 xmlns:jee="http://www.springframework.org/schema/jee"
                 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.1.xsd
                                       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.1.xsd
                                       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.1.xsd
                                       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.1.xsd
                                       http://jboss.com/products/seam/spring-seam http://jboss.com/products/seam/spring-seam-2.1.xsd
                                       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.1.xsd"
                 default-lazy-init="true">
            
               <tx:annotation-driven proxy-target-class="true" />
            
               <bean id="userManagerService" parent="manageUsersService" lazy-init="true">
                  <seam:component class="com.i2i.services.user.ManageUsersServiceImpl"/>
               </bean>
            
               <seam:configure-scopes/>
            </beans>
            



            service layer applicationContext.xml snippet:


               <bean id="sessionFactory"
                  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init="true">
                  <property name="dataSource" ref="${datasource}"/>
                  <property name="mappingLocations">
                     <value>classpath:com/i2i/domain/*.hbm.xml</value>
                  </property>
                  <property name="hibernateProperties">
                     <props>
                        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                        <prop key="hibernate.cache.use_query_cache">false</prop>
                        <prop key="hibernate.cache.use_second_level_cache">true</prop>
                        <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                        <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache-hibernate.xml</prop>
                        <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batchsize}</prop>
                     </props>
                  </property>
               </bean>
            
               <bean id="transactionManager"
                  class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
                  <property name="sessionFactory">
                     <ref local="sessionFactory" />
                  </property>
               </bean>
            
               <bean id="i2iDaoTarget" class="com.alas.i2i.dao.I2iDao" lazy-init="true">
                  <property name="sessionFactory">
                     <ref local="sessionFactory" />
                  </property>
                  <property name="defaultFetchSize" value="${dao.hibernate.defaultFetchSize}"/>
               </bean>
                 
               <bean id="i2iDao" parent="txProxyTemplate">
                  <property name="target">
                     <ref local="i2iDaoTarget" />
                  </property>
               </bean>
            
               <bean id="txProxyTemplate" lazy-init="true"
                  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
                  <property name="transactionManager">
                     <ref local="transactionManager" />
                  </property>
                  <property name="transactionAttributes">
                     <props>
                        <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                        <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                        <prop key="insert*">PROPAGATION_REQUIRED</prop>
                        <prop key="update*">PROPAGATION_REQUIRED</prop>
                        <prop key="delete*">PROPAGATION_REQUIRED</prop>
                     </props>
                  </property>
               </bean>
            
            
               <bean id="manageUsersService" class="com.alas.i2i.services.user.ManageUsersServiceImpl">
                  <property name="dao">
                     <ref bean="i2iDao"/>
                  </property>
               </bean>
            
            



            components.xml:



            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components" 
                        xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:spring="http://jboss.com/products/seam/spring"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:transaction="http://jboss.com/products/seam/transaction"
                        xmlns:ui="http://jboss.com/products/seam/ui"
                        xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                                            http://jboss.com/products/seam/spring http://jboss.com/products/seam/spring-2.1.xsd
                                      http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                                       http://jboss.com/products/seam/ui http://jboss.com/products/seam/ui-2.1.xsd
                                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd">
            
            
                <core:manager conversation-timeout="120000" 
                              concurrent-request-timeout="500" 
                              conversation-id-parameter="cid"/>
            
               <core:init debug="true"/>
                
               <persistence:managed-hibernate-session name="hibernateSession" auto-create="true" session-factory="#{sessionFactory}"/>
                 
               <spring:spring-transaction platform-transaction-manager="#{transactionManager}"/>
                 
               <ui:hibernate-entity-loader session="#{hibernateSession}"/>
                 
               <security:identity authenticate-method="#{authenticator.authenticate}"/>
                      
            </components>
            



            stack trace:


            10:55:28,206 ERROR [[/seam-test]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
            org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.IllegalStateException: No active application scope
                 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
                 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
                 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
                 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
                 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
                 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
                 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
                 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
                 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
                 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
                 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
                 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
                 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
                 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
                 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
                 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
                 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
                 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
                 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
                 at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
                 at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
                 at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
                 at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
                 at org.jboss.web.WebModule.startModule(WebModule.java:83)
                 at org.jboss.web.WebModule.startService(WebModule.java:61)
                 at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                 at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                 at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                 at $Proxy0.start(Unknown Source)
                 at org.jboss.system.ServiceController.start(ServiceController.java:417)
                 at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                 at $Proxy44.start(Unknown Source)
                 at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                 at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                 at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
                 at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
                 at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
                 at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
                 at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                 at $Proxy45.start(Unknown Source)
                 at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                 at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                 at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                 at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                 at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                 at $Proxy9.deploy(Unknown Source)
                 at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
                 at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
                 at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
                 at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
                 at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                 at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                 at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                 at $Proxy0.start(Unknown Source)
                 at org.jboss.system.ServiceController.start(ServiceController.java:417)
                 at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                 at $Proxy4.start(Unknown Source)
                 at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
                 at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                 at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                 at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                 at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                 at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                 at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                 at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                 at $Proxy5.deploy(Unknown Source)
                 at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
                 at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
                 at org.jboss.Main.boot(Main.java:200)
                 at org.jboss.Main$1.run(Main.java:508)
                 at java.lang.Thread.run(Thread.java:613)
            Caused by: java.lang.IllegalStateException: No active application scope
                 at org.jboss.seam.core.Init.instance(Init.java:110)
                 at org.jboss.seam.ioc.spring.SeamNamespaceHandler$SeamComponentBeanDefinitionDecorator.decorate(SeamNamespaceHandler.java:191)
                 at org.springframework.beans.factory.xml.NamespaceHandlerSupport.decorate(NamespaceHandlerSupport.java:106)
                 at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1284)
                 at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1273)
                 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:241)
                 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:153)
                 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:132)
                 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
                 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
                 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
                 ... 148 more
            10:55:28,207 ERROR [StandardContext] Error listenerStart
            10:55:28,207 ERROR [StandardContext] Context [/seam-test] startup failed due to previous errors
            
            



            Prior to the exception, the log conveys Seam component loading, which requires an active application context, doesn't it? So what's happening to the active application scope?


            HELP! PLEASE!




            • 4. Re: legacy spring service layer
              Guillaume Jeudy Master

              You need Seam to bootstrap the spring container and not the servlet container bootstrap the spring container.


              So remove:


              <listener>
                    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                 </listener>
              


              from your web.xml and add the following in your components.xml:


              <spring:context-loader config-locations="/WEB-INF/classes/applicationContext.xml" />



              Modify config-locations at your leisure, depending where your spring config resides..


              Let us know how it goes.

              • 5. Re: legacy spring service layer
                Robert Shanahan Newbie

                I did as you suggested. Recall from my ContextLoaderListener config that my appContext has a parent. I configured like this:


                components.xml



                    <spring:context-loader>
                         <spring:config-locations>
                              <value>classpath:com/i2i/services/beanRefFactory.xml</value>
                              <value>/WEB-INF/beanRefFactory.xml</value>
                         </spring:config-locations>
                    </spring:context-loader>
                



                /WEB-INF/beanRefFactory.xml



                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
                            "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
                
                <beans>
                     <bean id="i2i.web" lazy-init="false"
                          class="org.springframework.context.support.ClassPathXmlApplicationContext">
                          <constructor-arg>
                               <list>
                                    <value>
                                         /WEB-INF/applicationContext.xml
                                    </value>
                               </list>
                          </constructor-arg>
                          <constructor-arg>
                               <ref bean="i2i.services" />
                          </constructor-arg>
                     </bean>
                </beans>
                
                



                JBoss started cleanly, including loading of all Spring beans, and I was hopeful that something might actually work first try. No such luck. Seam can't find the PlatFormTransactionManager.



                17:53:39,969 DEBUG [DebugPageHandler] redirecting to debug page
                java.lang.IllegalStateException: Unable to find PlatformTransactionManager
                     at org.jboss.seam.ioc.spring.SpringTransaction.getPlatformTransactionManagerRequired(SpringTransaction.java:100)
                     at org.jboss.seam.ioc.spring.SpringTransaction.begin(SpringTransaction.java:67)
                     at org.jboss.seam.jsf.SeamPhaseListener.begin(SeamPhaseListener.java:594)
                     at org.jboss.seam.jsf.SeamPhaseListener.begin(SeamPhaseListener.java:584)
                     at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsBeforePhase(SeamPhaseListener.java:325)
                     at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:142)
                     at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:116)
                     at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
                     at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:522)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                     at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
                     at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                     at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                     at java.lang.Thread.run(Thread.java:613)
                



                Any ideas?



                • 6. Re: legacy spring service layer
                  Robert Shanahan Newbie

                  BTW, I was able to get the seam component working by setting auto create to false and using


                  @In(create=true)
                  


                  In this configuration, there was no issue finding the PlatformTransactionManager.


                  Nevertheless, I'd like to be able get the components.xml spring:context-loader working and still interested in ideas why using beanRefFactory.xml style Spring bean loading would be problematic.

                  • 7. Re: legacy spring service layer
                    Robert Shanahan Newbie

                    Looking at the source of the spring context-config class, I can see that this will never work. Are there any plans to support ContextSingletonBeanFactoryLocator style context loading so that multiple webapps can share the same service layer context plus allow for setting context's parent?

                    • 8. Re: legacy spring service layer
                      Guillaume Jeudy Master

                      I never tried a beanRefFactory.xml setup combined with Seam. Check out the JIRAs and file a new one if none exist that address your issue.


                      If your integration is mission-critical (there is no going back) then I suggest you override the Seam ContextLoader by declaring the same @Name but with a higher precedence Application and whip up your own implementation.


                      @Scope(ScopeType.APPLICATION)
                      @BypassInterceptors
                      @Startup(depends="org.jboss.seam.ioc.spring.springELResolver")
                      @Name("org.jboss.seam.ioc.spring.contextLoader")
                      @Install(value = false, precedence = APPLICATION)
                      public class ContextLoader
                      

                      • 9. Re: legacy spring service layer
                        Robert Shanahan Newbie

                        Thanks for the help.


                        New Jira issue:
                        https://jira.jboss.org/jira/browse/JBSEAM-3639


                        One last question as it relates to legacy Spring integration... all of the examples I've been able to find are based on Spring's Jpa template (EntityManager). Is it possible to create a Spring based persistence context with a traditional HibernateTemplate based persistence context? If so, how?


                        Examples look like this:


                        <persistence:managed-persistence-context name="entityManager"
                                                              auto-create="true" 
                                                              entity-manager-factory="#{entityManagerFactory}" />
                        



                        My legacy Spring service component has HibernateTemplate based DAOs that are based on Hibernate SessionFactory.


                        Is it correct to do this?:


                        <persistence:managed-persistence-context name="entityManager"
                                                              auto-create="true" 
                                                              entity-manager-factory="#{sessionFactory}" />
                        


                        If so, should the Spring DAOs then be injected with a SeamManagedSessionFactoryBean or a SeamManagedEntityManagerFactoryBean?


                        Or should the persistence context be defined in terms of Hibernate as in?:


                        <persistence:managed-hibernate-session name="hibernateSession" auto-create="true" session-factory="#{sessionFactory}"/>
                        





                        • 10. Re: legacy spring service layer
                          Guillaume Jeudy Master

                          If you are dealing with Spring's HibernateTemplate then I assume you use the SessionFactory not EntityManagerFactory in which case you will have to use the Seam native hibernate integration with:


                          <persistence:managed-hibernate-session name="hibernateSession" auto-create="true" session-factory="#{sessionFactory}"/>
                          



                          likewise inject a SeamManagedSessionFactoryBean in your Spring DAOs.


                          I don't see any reasons why this shouldnt work, both Seam native hibernate integration and JPA integration are symmetrical to the only difference of the programming API you get.