其他分享
首页 > 其他分享> > TransactionManager Spring 4休眠4 NoSuchMethodError

TransactionManager Spring 4休眠4 NoSuchMethodError

作者:互联网

我试图在春季使用基于注释的事务管理,这是我的春季配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xmlns="http://www.springframework.org/schema/beans" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"



        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            ">


    <bean id="dataSource" 
            class="org.apache.commons.dbcp.BasicDataSource" 
            depends-on="propertyPlaceholderConfigurer"
            p:driverClassName="org.postgresql.Driver"
            p:url="${db.url}" 
            p:username="${db.username}" 
            p:password="${db.password}" />


    <context:spring-configured />

    <bean id="sessionFactory" 
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" 
            depends-on="flywayAutomaticMigrationBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.example" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.default_schema">restProj</prop>
            </props>
        </property>

        <property name="mappingResources">
            <list>
                <value>com/example/db/hbm/user/User.hbm.xml</value>
                <value>com/example/db/hbm/user/Role.hbm.xml</value>
                <value>com/example/db/hbm/user/Feature.hbm.xml</value>

            </list>
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean> 

</beans>

当我运行项目时,出现以下错误:

Caused by: java.lang.NoSuchMethodError: org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Ljava/lang/Object;)V
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parseInternal(AnnotationDrivenBeanDefinitionParser.java:54)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:60)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1424)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1414)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
... 28 more

我读了answer,但是我不想降级我的春季版本.

感谢您的任何帮助.

____更新____
这是我的罐子清单:

    antlr-2.7.7.jar
aopalliance-repackaged-2.2.0.jar
asm-all-repackaged-2.2.0.jar
aspectjtools-1.7.4.jar
c3p0-0.9.1.2.jar
cas-client-core-3.2.1.jar
cas-client-integration-tomcat-common-3.2.1.jar
cas-client-integration-tomcat-v6-3.2.1.jar
cas-client-support-distributed-ehcache-3.2.1.jar
cas-client-support-distributed-memcached-3.2.1.jar
cglib-2.1.88.jar
commons-codec-1.6.jar
commons-collections.jar
commons-collections4-4.0.jar
commons-dbcp-1.4.jar
commons-exec-1.1.jar
commons-fileupload.jar
commons-io.jar
commons-lang-2.5.jar
commons-logging-1.1.3.jar
commons-pool-1.5.4.jar
dbunit-2.4.9.jar
dom4j-1.6.jar
ehcache-core-2.2.0.jar
flyway-core-3.0.jar
hamcrest-core-1.3.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.5.Final.jar
hibernate-entitymanager-4.3.5.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
HibernatePagedList-2.0.jar
hk2-api-2.2.0.jar
hk2-locator-2.2.0.jar
hk2-utils-2.2.0.jar
jackson-annotations-2.2.3.jar
jackson-core-2.2.3.jar
jackson-databind-2.2.3.jar
jackson-jaxrs-base-2.2.3.jar
jackson-jaxrs-json-provider-2.2.3.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
javax.annotation-api-1.2.jar
javax.inject-2.2.0.jar
javax.servlet-api-3.0.1.jar
javax.ws.rs-api-2.0.jar
jaxb-api-2.2.7.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-guava-2.6.jar
jersey-server.jar
jersey-spring3-2.6.jar
jta-1.0.1B.jar
juli-6.0.29.jar
junit-4.11.jar
log4j-1.2.15.jar
odmg-3.0.jar
org.osgi.core-4.2.0.jar
osgi-resource-locator-1.0.1.jar
PagedListApi-2.0.jar
persistence-api-1.0.jar
postgresql-8.4-703.jdbc4.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
spring-aop-4.0.2.RELEASE.jar
spring-aspects-4.0.2.RELEASE.jar
spring-beans-4.0.2.RELEASE.jar
spring-bridge-2.2.0-b14.jar
spring-context-4.0.2.RELEASE.jar
spring-context-support-4.0.2.RELEASE.jar
spring-core-4.0.2.RELEASE.jar
spring-dao-2.0.8.jar
spring-expression-4.0.2.RELEASE.jar
spring-instrument-4.0.2.RELEASE.jar
spring-instrument-tomcat-4.0.2.RELEASE.jar
spring-jdbc-4.0.2.RELEASE.jar
spring-orm-4.0.2.RELEASE.jar
spring-security-acl-3.2.1.RELEASE.jar
spring-security-cas-3.2.1.RELEASE.jar
spring-security-config-3.2.1.RELEASE.jar
spring-security-core-3.2.1.RELEASE.jar
spring-security-ldap-3.2.1.RELEASE.jar
spring-security-openid-3.2.1.RELEASE.jar
spring-security-taglibs-3.2.1.RELEASE.jar
spring-security-web-3.2.1.RELEASE.jar
spring-tx-4.0.2.RELEASE.jar
spring-web-4.0.2.RELEASE.jar
validation-api-1.1.0.Final.jar
xml-apis-1.4.01.jar
xmlsec-1.3.0.jar

解决方法:

您需要使用相同版本的Spring框架.
您在Spring的第4版中拥有大多数依赖项,但同时也有

spring-dao-2.0.8.jar和spring-bridge-2.2.0-b14.jar.

删除那些依赖项,它应该可以工作

标签:spring-transactions,hibernate,spring
来源: https://codeday.me/bug/20191029/1958103.html