2013-04-09 153 views
0

我使用Spring 3.2和Hibernate4。我包括所有需要的罐子。使用JBoss AS。从Eclipse部署。但我得到这个错误。NoSuchMethodError:LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'personController': Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private 
com.springmvcsample.service.PersonService 
com.springmvcsample.controller.PersonController.personService; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'personService': Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private 
com.springmvcsample.dao.PersonDAO com.springmvcsample.service.PersonServiceImpl.personDao; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'personDao': Injection of autowired dependencies failed; nested exception is  
org.springframework.beans.factory.BeanCreationException: Could not autowire field: 
org.hibernate.SessionFactory com.springmvcsample.dao.PersonDAOImpl.sessionFactory; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'sessionFactory' defined in ServletContext resource [/WEB-INF/hibernate_config.xml]: 
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: 
org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass 
(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration; 

Web.xml中

<servlet> 
    <servlet-name> SpringMVC_Hibernate</servlet-name> 
    <servlet-class> 
       org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WEB-INF/SpringMVC_Hibernate-servlet.xml</param-value> 
    </context-param> 

<servlet-mapping> 
    <servlet-name>SpringMVC_Hibernate</servlet-name> 
    <url-pattern>*.htm</url-pattern> 
</servlet-mapping> 

SpringMVC_Hibernate-servlet.xml中

 <context:component-scan base-package="com.springmvcsample.controller"/> 
    <context:component-scan base-package="com.springmvcsample.dao"/> 
    <context:component-scan base-package="com.springmvcsample.service"/> 
    <import resource="hibernate_config.xml"/> 

    <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/> 
    <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> 
     <!-- Turn off working out content type based on URL file extension, should fall back to looking at the Accept headers --> 
     <property name="favorPathExtension" value="false" /> 
    </bean> 

    <bean name="sender" class="com.springmvcsample.utility.MessageSender"/> 

hibernate_config.xml

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations"> 
     <list> 
      <value>/resources/db.properties</value> 
     </list> 
    </property> 
</bean> 

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
    <property name="url" value="${jdbc.url}" /> 
    <property name="username" value="${jdbc.user}" /> 
    <property name="password" value="${jdbc.password}" /> 
</bean> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="packagesToScan" value="com.springmvcsample.controller" /> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
      <prop key="hibernate.show_sql">true</prop> 

     </props> 
    </property> 
</bean> 

<tx:annotation-driven transaction-manager="transactionManager"/> 

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

my lib flder

其他罐子包括:

spring-jms-3.2x.jar 
    spring-orm-*.jar 
    spring-tx-*.jar 
    spring-web-*.jar 
    spring-webmvc-*.jar 
+0

所有春天罐子从3.2.0右 – 2013-04-09 03:46:46

+0

这就是正确的。所有版本都是相同的版本3.2.0 – 2013-04-09 03:49:06

+0

这些库实际上是否包含在war文件中? – Kai 2013-04-09 09:14:13

回答

1

使用Maven让生活在这样的情况下更容易。

打开的pom.xml在这样的Eclipse IDE/STS会给你一个更好的画面类似以下内容: -

enter image description here

+0

感谢您的信息! – 2013-08-26 17:02:22