Mysqldbでの構成にspringとhibernateを使用しています。
私のwe.xmlファイルには次のコードがあります:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://Java.Sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://Java.Sun.com/xml/ns/javaee http://Java.Sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/applicationcontext.xml</param-value>
</context-param>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
私のapplicationcontext.xmlファイルには次のインポートがあります:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="autodetect">
<import resource="spring-config/spring-common-applicationContext.xml"/>
<import resource="spring-config/spring-db-applicationContext.xml"/>
<import resource="spring-config/spring-dao-applicationContext.xml"/>
<import resource="spring-config/spring-processor-applicationContext.xml"/>
<import resource="spring-config/spring-security-processor-applicationContext.xml"/>
<import resource="spring-config/spring-service-applicationContext.xml"/>
<import resource="spring-config/spring-security-service-applicationContext.xml"/>
</beans>
私のspring-db-applicationContext.xmlには次のコードがあります:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="autodetect">
<!-- Hibernate session factory -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<constructor-arg index="0">
<value>${driverClassName}</value>
</constructor-arg>
<constructor-arg index="1">
<value>${url}</value>
</constructor-arg>
<constructor-arg index="2">
<value>${username}</value>
</constructor-arg>
<constructor-arg index="3">
<value>${password}</value>
</constructor-arg>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>WEB-INF/classes/hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<value> com.sufalam.mailserver.business.service.IUserProcessor.*=PROPAGATION_REQUIRED,-Java.lang.Exception
</value>
</property>
</bean>
</beans>
適切なライブラリを含めました。プロジェクトの実行時に、次のエラーが発生します:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionFactory' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Unsatisfied dependency expressed through bean property 'eventListeners': : Error creating bean with name 'transactionManager' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.Java:1141)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1034)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:289)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:286)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:188)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:526)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:730)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:387)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.Java:270)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.Java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.Java:47)
at org.Apache.catalina.core.StandardContext.listenerStart(StandardContext.Java:3934)
at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4429)
at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:791)
at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:771)
at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:526)
at org.Apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.Java:630)
at org.Apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.Java:556)
at org.Apache.catalina.startup.HostConfig.deployApps(HostConfig.Java:491)
at org.Apache.catalina.startup.HostConfig.start(HostConfig.Java:1206)
at org.Apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.Java:314)
at org.Apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.Java:119)
at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1053)
at org.Apache.catalina.core.StandardHost.start(StandardHost.Java:722)
at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
at org.Apache.catalina.core.StandardEngine.start(StandardEngine.Java:443)
at org.Apache.catalina.core.StandardService.start(StandardService.Java:516)
at org.Apache.catalina.core.StandardServer.start(StandardServer.Java:710)
at org.Apache.catalina.startup.Catalina.start(Catalina.Java:583)
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:597)
at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:288)
at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.Java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.Java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.Java:1299)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1061)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:289)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:286)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:188)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.Java:807)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:735)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:666)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.Java:1126)
... 37 more
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.Java:157)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.Java:109)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.Java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:243)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:188)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.Java:322)
... 50 more
誰かが解決策を持っていますか、なぜ私のsessionFactory Beanがエラーを出しているのですか?
前もって感謝します...
Springは問題が何であるかを正確に伝えています。ログとネストされたエラーメッセージを読むだけです。
Beanプロパティ 'sessionFactory'の設定中に、Bean'sessionFactory 'への参照を解決できません。ネストされた例外はorg.springframework.beans.factory.BeanCurrentlyInCreationExceptionです: 'sessionFactory'という名前のBeanの作成中にエラーが発生しました:現在作成中のFactoryBeanがgetObjectからnullを返しました
Googleで少し検索すると、このエラーメッセージは通常 循環依存 の結果であり、 推奨するメーリングリストの投稿 からdefault-autowire="detect"
を削除することになります。 <beans>
要素。