2011-10-13 74 views
1

我試着搜索論壇這個錯誤,但能找到其中一個回答我的查詢。 當我嘗試從spring-hibernate xml遷移到spring-hibernate註釋時,我遇到了一個錯誤。該錯誤是java.lang.IllegalStateException

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:955) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:901) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) 
at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1190) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103) 
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010) 
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957) 
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284) 
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279) 
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) 
at java.lang.Thread.run(Thread.java:619) 

我的分發程序Servlet看起來像下面

<?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:context="http://www.springframework.org/schema/context" 
xmlns:p="http://www.springframework.org/schema/p" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation=" 

http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

http://www.springframework.org/schema/context 

http://www.springframework.org/schema/context/spring-context-3.0.xsd 

http://www.springframework.org/schema/tx 

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

<!--<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />--> 

    <context:component-scan base-package="com.vaannila" /> 
    <tx:annotation-driven /> 



<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
    <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> 
    <property name="url" value="jdbc:derby://localhost:1527/seed"/> 
    <property name="username" value="root"/> 
    <property name="password" value="root"/> 
</bean> 

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="myDataSource" /> 
    <property name="annotatedClasses"> 
     <list> 
      <value>com.vaannila.domain.User</value> 
     </list> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.hbm2ddl.auto">create</prop> 
     </props> 
    </property> 
</bean> 

<!--<bean id="myUserDAO" class="com.vaannila.dao.UserDAOImpl"> 
    <property name="sessionFactory" ref="mySessionFactory"/> 
</bean> 

<bean name="/user/*.htm" class="com.vaannila.web.UserController" > 
    <property name="userDAO" ref="myUserDAO" /> 
</bean>--> 

    <bean id="transactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

任何人都可以在這裏幫我儘快?

由於提前

回答

4

嵌套的例外是java.lang.IllegalStateException:沒有bean類 在bean定義指定

你需要在這裏指定的事務管理類

<bean id="transactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

可能是你需要這個類

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager""> 
      <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 
+0

謝謝隊友。這就像魅力一樣。 – Junaidaj

+0

不客氣:)(也是upvote&接受它作爲答案,因爲它:)) –

0

錯誤日誌告訴你清楚。您指定了bean(實例)的ID,而不指定它應該實例化的類。

相關問題