Results 1 to 2 of 2

Thread: [SPRING] Multiple sessions factories

  1. #1

    Default [SPRING] Multiple sessions factories

    Good morning, people.

    I'm in a first project using Spring and I need some help here.
    I want that one manager transaction takes care about two session factories.


    Code:
    	public final static ApplicationContext APPLICATION_CONTEXT = new FileSystemXmlApplicationContext(BusinessService.class.getResource("/applicationContext.xml").getFile());
    This exception is launched when the code above is performed:

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artigoBO' defined in file [H:\projetos\castor\br.edu.mba.artigo\bin\applicationContext.xml]: Cannot resolve reference to bean 'sessionFactoryXML' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryXML' defined in file [H:\projetos\castor\br.edu.mba.artigo\bin\applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [H:\projetos\castor\br.edu.mba.artigo\bin\applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sessionFactory' is required
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
    	at br.edu.mba.artigo.bus.BusinessService.<clinit>(BusinessService.java:12)
    Thanks for help.

  2. #2

    Default

    applicationContext.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	   xmlns:tx="http://www.springframework.org/schema/tx"
    	   xmlns:aop="http://www.springframework.org/schema/aop" 
    	   xmlns:context="http://www.springframework.org/schema/context"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    	   					   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    	   					   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    	   					   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
    	   					   default-autowire="byName" >
    
    	
    
    	<context:component-scan base-package="br.edu.mba.artigo.bus.bo" />
    	
    	<!-- ************************************ Beans de fabrica de sessão ****************************** -->
    
    	<bean id="sessionFactoryRelacional"  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="configLocation"
    			value="classpath:hibernate_usuarios.cfg.xml">
    		</property>
    	</bean>
    	
    	<bean id="sessionFactoryXML" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="configLocation"
    			value="classpath:hibernate_artigos.cfg.xml">
    		</property>
    	</bean>
    	
    	<!-- *********************************** Beans de negócio **************************************** -->
    	
    	<bean id="artigoBO" class="br.edu.mba.artigo.bus.bo.ArtigoBO" >
    		<property name="sessionFactory">
    			<ref  local="sessionFactoryXML"/>
    		</property>
    	</bean>
    	
    	<bean id="usuarioBO" class="br.edu.mba.artigo.bus.bo.UsuarioBO" >
    		<property name="sessionFactory">
    			<ref  local="sessionFactoryRelacional"/>
    		</property>
    	</bean>
    	
    	<!-- *********************************** Controle de Transação ************************************* -->
     	
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
    	</bean>
    	
    	<tx:annotation-driven />
    	
    </beans>
    UsuarioBO and ArtigoBO extend HibernateDaoSupport.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •