Java 如何配置Spring以使用TransactionManager

Java 如何配置Spring以使用TransactionManager,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,我试图了解如何使用SpringDataSourceTransactionManager 我正试着跟着这个。 但是,当我从Eclipse启动Tomcat时,会出现以下错误: SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.NoClassDefFoundErr

我试图了解如何使用Spring
DataSourceTransactionManager

我正试着跟着这个。 但是,当我从Eclipse启动Tomcat时,会出现以下错误:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getDeclaredMethods(Unknown Source)
    at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:159)
    at org.springframework.context.annotation.ConfigurationClassUtils.isLiteConfigurationCandidate(ConfigurationClassUtils.java:106)
    at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:87)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:257)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:227)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:623)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 23 more
这是DispatcherServlet.xml的相关代码

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

        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="create" />
            </tx:attributes>
        </tx:advice>

        <aop:config>
            <aop:pointcut id="userDaoTxPointcut" expression="execution(* com.springgestioneerrori.DAO.UtenteDAO.salvaUtente(..))" />
            <aop:advisor advice-ref="txAdvice" pointcut-ref="userDaoTxPointcut" />
        </aop:config>   


salvaUtente()是我将处理多个
插入的方法(现在仍然是exmpty)。

类路径中缺少一个jar:


org.aspectj
aspectjweaver
${aspectjweaver.version}

类路径中缺少jar:


org.aspectj
aspectjweaver
${aspectjweaver.version}

如果它是用
@Transactional
注释的,那么您究竟为什么要使用基于xml的tx配置?删除
tx:advice
aop:config
并添加
tx:annotation-driven
。这个错误与类路径上缺少依赖项有关(可能是aspectjrt.jar或aspectjweaver.jar)。对不起,我正在编辑另一篇文章,我忘了删除那句话,实际上我没有注释。无论如何,我将aspectj-1.6.9添加到我的类路径中,我得到了相同的错误。如果它是用
@Transactional
注释的,那么你到底为什么要使用基于xml的tx配置?删除
tx:advice
aop:config
并添加
tx:annotation-driven
。这个错误与类路径上缺少依赖项有关(可能是aspectjrt.jar或aspectjweaver.jar)。对不起,我正在编辑另一篇文章,我忘了删除那句话,实际上我没有注释。无论如何,我将aspectj-1.6.9添加到我的类路径中,得到了相同的错误。我将aspectj-1.6.9添加到我的类路径中,得到了相同的错误error@MatteoDepasquali您需要aspectjweaver。看,我在类路径中添加了aspectj-1.6.9,得到了相同的结果error@MatteoDepasquali您需要aspectjweaver。看见