我相当确信有一些课程或罐子问题正在进行,但我不清楚它是什么。 beanName错误不会在任何类型的搜索上显示非常有用的数据。当我收到错误时,我正试图在Tomcat 8上启动它。我正在运行hibernate 5.这是我的错误:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/data.xml]: 'beanName' must not be empty; nested exception is java.lang.IllegalArgumentException: 'beanName' must not be empty
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:223)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:222)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1404)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1394)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: 'beanName' must not be empty
at org.springframework.util.Assert.hasText(Assert.java:168)
at org.springframework.beans.factory.config.RuntimeBeanReference.<init>(RuntimeBeanReference.java:58)
at org.springframework.beans.factory.config.RuntimeBeanReference.<init>(RuntimeBeanReference.java:46)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:178)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82)
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:220)
... 18 more
以下是data.xml中引用的bean:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" >
<property name="dataSource" ref="${database.dataSource}" />
<property name="annotatedClasses">
<list>
<value>com.adilly.giftlist.model.BaseEntity</value>
<value>com.adilly.giftlist.model.EmailOptOut</value>
<value>com.adilly.giftlist.model.Event</value>
<value>com.adilly.giftlist.model.EventComment</value>
<value>com.adilly.giftlist.model.EventUser</value>
<value>com.adilly.giftlist.model.PersistentLogins</value>
<value>com.adilly.giftlist.model.User</value>
<value>com.adilly.giftlist.model.WishItem</value>
<value>com.adilly.giftlist.model.WishItemComment</value>
<value>com.adilly.giftlist.model.WishItemReservation</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${database.dialect}</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.connection.autoReconnect">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">${database.showSQL}</prop>
<!--
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
-->
</props>
</property>
</bean>
答案 0 :(得分:2)
问题在于您将属性指向数据源!
<property name="dataSource" ref="${database.dataSource}" />
您应该使用id&#34; datasource&#34;创建一个bean。并在你的sessionFactory上反驳它!看看这个例子:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}"/>
</bean>
然后,在sessionFactory
上,更改为:
<property name="dataSource" ref="dataSource" />