2016-12-14 171 views
2

我相當有信心有一些類或jar問題正在進行,但我不清楚看到它是什麼。 beanName錯誤在任何類型的搜索中都沒有提供非常有用的數據。我試圖在Tomcat 8上啓動它,當我得到錯誤。我在休眠5.運行這是我的錯誤:beanName不能爲空

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> 

回答

1

的問題是,你都指向一個屬性的數據源!

<property name="dataSource" ref="${database.dataSource}" /> 

您應該創建一個ID爲「datasource」的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" /> 

看看Spring JDCB Documentation here

+0

因此,在這種應用中,還有其他一些豆類參考像這樣一個屬性,它是$ {database.SOMEITEM}我應該設置這個bean來保存它裏面的所有值以及它們需要指向的位置嗎? – facon12

+0

問題@ falcon12是來自sessiomFactory的屬性dataSource不希望從外部配置屬性,而是一個Speing bean!你應該像我向你解釋的那樣創建數據源bean。 – BrunoDM

+0

它是有道理的。對於更多的上下文,我繼承了這個應用程序的當前狀態,所以我正在解決它的問題。我被告知它正在運行的狀態,但我很懷疑。我是一個.net開發者,所以豆類有點難以爲我處理。我會通過這個工作並回來接受解決方案,只要給我一點時間。 – facon12