【问题标题】:Spring Transaction Manager (Annotation Style) Runtime ErrorSpring 事务管理器(注释样式)运行时错误
【发布时间】:2012-02-28 03:46:53
【问题描述】:

因此,当我在 glassfish 应用程序服务器中加载我的战争时,基本上我遇到了一个异常。我将 Spring 的事务管理器与我的 mysql 数据库一起使用。报错(全栈跟踪)如下:

java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.getAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;

我的applicationContext.xml文件如下:

<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:sws="http://www.springframework.org/schema/web-services"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:oxm="http://www.springframework.org/schema/oxm"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-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/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

    <context:property-placeholder location="classpath:testjdbc.properties"/>

    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="txManager"/>

      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="passwprd" value="${jdbc.password}" />
      </bean>

      <bean name="licenseGenService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
        <property name="service" ref="LicensingDaoImpl"/>
        <property name="serviceInterface" value="mypackage.LicensingDao"/>
      </bean>

      <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name ="dataSource" ref="dataSource" />
      </bean>

      <bean id="licenseDAO" class = "myPackage.LicenseDao">
        <constructor-arg ref="dataSource" />
      </bean>

      <bean id="licenseGenerator" class ="myPackage.LicenseGeneratorImpl">
        <constructor-arg ref = "licenseDAO" />
      </bean>

</beans>

我发现这个错误非常神秘,因为它所抱怨的类甚至不在我的应用程序上下文中。顺便说一句,我正在使用 Spring 3.1。感谢您的任何建议或帮助。

【问题讨论】:

标签: java spring exception transactions


【解决方案1】:

查看您的类路径并确保那里只有 一个 版本的所有 Spring 依赖项。

【讨论】:

  • 查看 Tomasz 在下面的回答,即:确保所有 Spring JAR 也使用相同的版本!
  • 我只有 Spring 依赖项(3.2.2)的版本,但仍然出现相同的错误。我正在尝试将我的项目从硬连线 jar 文件配置迁移到基于 maven 的配置。
  • 已修复...我认为我错误地在 Maven 中包含了旧版本的 Spring,但已将其更改回最新版本。我已经更新了源、项目、重新启动服务器、关闭 Eclipse 并重新启动,但出现此错误。我从 eclipse 中删除了服务器配置并添加了一个新配置。这次成功了。
【解决方案2】:

显然您的应用程序正在使用旧版本的spring-core*.jar。确保所有 Spring JAR 都是 3.1.x 版本,并且没有重复。

spring-core*.jar 包含 3.1 中引入的 AnnotationUtils.getAnnotation() 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 2011-03-22
    • 2023-04-03
    • 2012-12-14
    • 1970-01-01
    相关资源
    最近更新 更多