Bom dia, pessoal.
Estou em um primeiro projeto utilizando Spring e já fazendo algo diferente…rsrs.
Estou precisando definir para beans diferentes sessionFactory.
Estes beans extendem HibernateDaoSuport.
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>[/code]
Obs.: UsuarioBO e ArtigoBO extendem HibernateDaoSupport.
Exceção lançada quando executo o seguinte código:
public final static ApplicationContext APPLICATION_CONTEXT = new FileSystemXmlApplicationContext(BusinessService.class.getResource("/applicationContext.xml").getFile());
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)
Agradeço qualquer ajuda.