【问题标题】:WEB-INF/classes vs WEB-INF/lib in Jetty 7Jetty 7 中的 WEB-INF/classes 与 WEB-INF/lib
【发布时间】:2012-09-27 22:52:12
【问题描述】:

当我将我的类打包到 WEB-INF/classes 中时,我没有参与事务的 Spring @Transactional 方法(或任何与切入点定义匹配的方法)。我在日志中遇到了很多“未找到 Hibernate 会话,配置不允许...”异常。令人费解的是,在堆栈跟踪中,我可以看到 CGLIB 增强类,所以它似乎被代理了,但似乎没有创建新事务。

但是,如果我将 相同的类 打包到一个 jar 文件中并将该 jar 放在 WEB-INF/lib 中,则应用程序可以正常工作!交易已创建等,这里发生了什么?为什么类在WEB-INF/classes下不起作用?

Spring事务配置如下:

<aop:aspectj-autoproxy proxy-target-class="true" />
<context:component-scan base-package="com.example" />
<tx:annotation-driven transaction-manager="txManager"/>

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:advice id="serviceAdvice" transaction-manager="txManager">      
    <tx:attributes>
        <tx:method name="save*"/>
        <tx:method name="update*"/>
        <tx:method name="delete*"/>   
        <tx:method name="*" read-only="true"/>
    </tx:attributes> 
</tx:advice>

<aop:config>        
    <aop:pointcut id="servicePointcut" expression="execution(* com.example.service.*.*Service*.*(..))"/>            
    <aop:advisor advice-ref="serviceAdvice" pointcut-ref="servicePointcut"/>
</aop:config>

FWIW,我正在使用 Jetty 7.4 和 Spring 3.1.2。

关于我应该寻找什么的任何线索?

更新:

我启用了 Spring 事务日志,我可以看到:

28 Sep 2012 15:07:16,126 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [save*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
28 Sep 2012 15:07:16,133 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [update*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
28 Sep 2012 15:07:16,134 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [delete*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
28 Sep 2012 15:07:16,136 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly]

但是到了实际在事务方法中工作的时候,它就爆出不允许创建事务的异常。

【问题讨论】:

    标签: jakarta-ee jetty spring-transactions


    【解决方案1】:

    从外观上看,正在扫描该注释的任何内容都只是处理 jar,而不是 WEB-INF/classes 下的类

    [edit] jetty 没有扫描这些注释

    【讨论】:

    • 谢谢杰西!我了解 Jetty 并没有扫描这些注释及其 Spring 的作用,并且它应该被拾取在 webapp 中。但此时我不知道在哪里看,因此也扔进了 Jetty 标签。
    猜你喜欢
    • 2011-06-11
    • 1970-01-01
    • 2012-01-11
    • 2013-06-20
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    相关资源
    最近更新 更多