Spring事务管理器(注释样式)运行时错误

时间:2012-02-06 17:01:54

标签: java spring exception transactions

基本上,当我在glassfish应用程序服务器中加载战争时,我得到一个例外。我在我的mysql数据库中使用Spring的事务管理器。报告的错误(完整堆栈跟踪)如下:

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>

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

2 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:4)

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

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

相关问题