【发布时间】:2017-07-02 22:51:00
【问题描述】:
我目前正在为我的项目使用 Spring Security。 添加此 bean 后(记住我功能的用户):
<b:bean id="jdbcTokenRepository" class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl">
<b:property name="createTableOnStartup" value="false"/>
<b:property name="dataSource" ref="dataSource"/>
</b:bean>
用户令牌仍未保存。都是因为 'dataSource' 被配置为 autoCommit=false。
所以我做的第一件事是(真的很丑,因为我必须再创建一个类,但它正在工作):
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public class TransactionalJdbcTokenRepositoryImpl extends JdbcTokenRepositoryImpl {}
对我来说更好的解决方案如下:
<b:bean id="jdbcTokenRepository"
class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl">
<b:property name="createTableOnStartup" value="false"/>
<b:property name="dataSource" ref="dataSource"/>
</b:bean>
<tx:advice id="tokenRepoAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="false" expose-proxy="false">
<aop:advisor id="tokenRepoAdvisor"
advice-ref="tokenRepoAdvice"
pointcut="bean(jdbcTokenRepository)"/>
</aop:config>
纯 XML 没有不必要的类:
但由于某种原因,spring 现在需要 aspectj!
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 68 more
为什么?如果没有这个配置,我的 dao 层在 @Transactional 注释下工作得很好。如何避免添加 aspectj 库但仍保留 xml 配置?
【问题讨论】:
标签: java spring transactions aop aspectj