Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse NoSuchMethodError:LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;_Eclipse_Hibernate_Spring Mvc_Jboss_Nosuchmethod - Fatal编程技术网

Eclipse NoSuchMethodError:LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;

Eclipse NoSuchMethodError:LocalSessionFactoryBuilder.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;,eclipse,hibernate,spring-mvc,jboss,nosuchmethod,Eclipse,Hibernate,Spring Mvc,Jboss,Nosuchmethod,我正在使用Spring3.2和Hibernate4。我包括了所有需要的罐子。使用JBoss作为代理。从Eclipse部署。但我得到了这个错误 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personController': Injection of autowired dependencies failed; nested exception is org.sp

我正在使用Spring3.2和Hibernate4。我包括了所有需要的罐子。使用JBoss作为代理。从Eclipse部署。但我得到了这个错误

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>

在这种情况下,使用Maven会使生活更轻松

在IDE(如Eclipse/STS)中打开pom.xml,可以更好地了解以下情况:-


所有弹簧罐都是3.2.0版本的,没错。所有版本都是相同的3.2.0版本。war文件中是否包含这些库?另外,请确保您的某个地方没有旧版本。当我经常看到这个错误时,这是因为我要么有冲突的JAR版本(需要版本x.x.x,但我有x.y.z),要么我有两个副本,一个旧的不正确,一个新的正确,而旧的先被加载。另外,您是在使用Maven或其他工具来管理您的依赖关系,还是在手工操作?我是在手工操作。我下载了所有可用的最新版本。Spring3.2.0和Hibernate4.0。有没有办法检查库之间的版本依赖关系?都是罐子。它是一个Eclipse部署到JBoss的组件。所以这是一场战争。
        <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"/>
  <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>
  spring-jms-3.2x.jar 
  spring-orm-*.jar
  spring-tx-*.jar
  spring-web-*.jar
  spring-webmvc-*.jar