Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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
如何解决java.lang.NoSuchMethodError:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass_Spring_Hibernate_Maven - Fatal编程技术网

如何解决java.lang.NoSuchMethodError:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass

如何解决java.lang.NoSuchMethodError:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass,spring,hibernate,maven,Spring,Hibernate,Maven,运行项目时,会出现此异常 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ressourceDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not

运行项目时,会出现此异常

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ressourceDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory ma.controle.gestion.dao.RessourceDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.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;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
<bean id="structure" class="ma.controle.gestion.model.Structure"/>
<bean id="ressource" class="ma.controle.gestion.model.Ressource"/>

<bean id="ressourceDao"     class="ma.controle.gestion.dao.RessourceDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureDao"     class="ma.controle.gestion.dao.StructureDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureService" class="ma.controle.gestion.service.StructureServiceImpl">
    <property name="structureDao" ref="structureDao"></property>
</bean>
<bean id="ressourceService" class="ma.controle.gestion.service.RessourceService">
    <property name="ressourceDao" ref="ressourceDao"></property>        
</bean> 

   <!--Hibernate-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/controlegestion?useUnicode=true&amp;characterEncoding=utf-8"/>
    <property name="user" value="user"/>
    <property name="password" value=""/>
    <property name="minPoolSize" value="10"/>
    <property name="maxPoolSize" value="20"/>
    <property name="maxIdleTime" value="30"/>
    <property name="acquireIncrement" value="3"/>
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>ma.controle.gestion.model.Ressource</value>
            <value>ma.controle.gestion.model.Affectation</value>
            <value>ma.controle.gestion.model.Structure</value>
            <value>ma.controle.gestion.model.Activite</value>
        </list>
    </property>
    <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="txManager" />
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
以下是我的配置文件:

<bean id="structure" class="ma.controle.gestion.model.Structure"/>
<bean id="ressource" class="ma.controle.gestion.model.Ressource"/>

<bean id="ressourceDao"     class="ma.controle.gestion.dao.RessourceDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureDao"     class="ma.controle.gestion.dao.StructureDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureService" class="ma.controle.gestion.service.StructureServiceImpl">
    <property name="structureDao" ref="structureDao"></property>
</bean>
<bean id="ressourceService" class="ma.controle.gestion.service.RessourceService">
    <property name="ressourceDao" ref="ressourceDao"></property>        
</bean> 

   <!--Hibernate-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/controlegestion?useUnicode=true&amp;characterEncoding=utf-8"/>
    <property name="user" value="user"/>
    <property name="password" value=""/>
    <property name="minPoolSize" value="10"/>
    <property name="maxPoolSize" value="20"/>
    <property name="maxIdleTime" value="30"/>
    <property name="acquireIncrement" value="3"/>
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>ma.controle.gestion.model.Ressource</value>
            <value>ma.controle.gestion.model.Affectation</value>
            <value>ma.controle.gestion.model.Structure</value>
            <value>ma.controle.gestion.model.Activite</value>
        </list>
    </property>
    <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="txManager" />
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<bean id="structure" class="ma.controle.gestion.model.Structure"/>
<bean id="ressource" class="ma.controle.gestion.model.Ressource"/>

<bean id="ressourceDao"     class="ma.controle.gestion.dao.RessourceDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureDao"     class="ma.controle.gestion.dao.StructureDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureService" class="ma.controle.gestion.service.StructureServiceImpl">
    <property name="structureDao" ref="structureDao"></property>
</bean>
<bean id="ressourceService" class="ma.controle.gestion.service.RessourceService">
    <property name="ressourceDao" ref="ressourceDao"></property>        
</bean> 

   <!--Hibernate-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/controlegestion?useUnicode=true&amp;characterEncoding=utf-8"/>
    <property name="user" value="user"/>
    <property name="password" value=""/>
    <property name="minPoolSize" value="10"/>
    <property name="maxPoolSize" value="20"/>
    <property name="maxIdleTime" value="30"/>
    <property name="acquireIncrement" value="3"/>
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>ma.controle.gestion.model.Ressource</value>
            <value>ma.controle.gestion.model.Affectation</value>
            <value>ma.controle.gestion.model.Structure</value>
            <value>ma.controle.gestion.model.Activite</value>
        </list>
    </property>
    <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="txManager" />
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

我浪费了很多时间来查找错误,但我做不到,我需要帮助Pleaaase

您正在使用maven pom中定义的spring 4.1.5版,为什么要使用3.0版的XSD?从配置文件中的定义中删除版本,例如更改
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
以便spring自动为您选择正确的XSD。谢谢你的重播,我将xsd改为spring-beans.xsd-spring-context.xsd-spring-tx.xsd,但问题仍然存在。你是否使用此
将包放在配置文件中?否则,使用
@Autowired
spring将无法找到您正在调用的类,因为您没有定义应该在哪里找到它们。因此,如果您没有这个,您必须将它添加到您正在使用的任何包的配置中
context
xmlns:context=”的命名空间http://www.springframework.org/schema/context“
顺便说一句,第一条评论不是重点,只是一个提示;)。我的代码中已经有这一行,我在实习期间因为这个错误损失了5天:(:(
<bean id="structure" class="ma.controle.gestion.model.Structure"/>
<bean id="ressource" class="ma.controle.gestion.model.Ressource"/>

<bean id="ressourceDao"     class="ma.controle.gestion.dao.RessourceDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureDao"     class="ma.controle.gestion.dao.StructureDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="structureService" class="ma.controle.gestion.service.StructureServiceImpl">
    <property name="structureDao" ref="structureDao"></property>
</bean>
<bean id="ressourceService" class="ma.controle.gestion.service.RessourceService">
    <property name="ressourceDao" ref="ressourceDao"></property>        
</bean> 

   <!--Hibernate-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/controlegestion?useUnicode=true&amp;characterEncoding=utf-8"/>
    <property name="user" value="user"/>
    <property name="password" value=""/>
    <property name="minPoolSize" value="10"/>
    <property name="maxPoolSize" value="20"/>
    <property name="maxIdleTime" value="30"/>
    <property name="acquireIncrement" value="3"/>
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>ma.controle.gestion.model.Ressource</value>
            <value>ma.controle.gestion.model.Affectation</value>
            <value>ma.controle.gestion.model.Structure</value>
            <value>ma.controle.gestion.model.Activite</value>
        </list>
    </property>
    <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="txManager" />
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>