2008-03-10
acegi TransactionInterceptor遇到spring2.x
一直使用spring2.x都没有问题,所有service都通过AOP注入。
现在用acegi的ACL,却发现原来的AOP影响而不能使用。以下是我的AOP
<!-- Transactional advice -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- methods starting with 'save', 'update' or 'remove' use the default transaction settings -->
<tx:method name="save*"/>
<tx:method name="delete*"/>
<tx:method name="merge*"/>
<tx:method name="remove*"/>
<!-- other methods are set to read only -->
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* cn.biaoming.service..*Service.*(..))" advice-ref="txAdvice"/>
</aop:config>
而TransactionInterceptor是这么定义的:
<bean id="articleService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="cn.biaoming.service.ArticleService"/>
<property name="target"><ref local="articleServiceTager"/></property>
<property name="interceptorNames">
<list>
<idref local="articleServiceSecurity"/>
</list>
</property>
</bean>
<bean id="articleServiceSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="businessAccessDecisionManager"/></property>
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource">
<value>
</value>
</property>
</bean>
现在只要把spring2.x 的AOP去掉,TransactionInterceptor就能正常工作,要不就报以下错误
WARN Cglib2AopProxy.doValidateClass(250) | Unable to proxy method [public final java.util.List $Proxy29.getLatestArticle(java.lang.String,int)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
现在用acegi的ACL,却发现原来的AOP影响而不能使用。以下是我的AOP
<!-- Transactional advice -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- methods starting with 'save', 'update' or 'remove' use the default transaction settings -->
<tx:method name="save*"/>
<tx:method name="delete*"/>
<tx:method name="merge*"/>
<tx:method name="remove*"/>
<!-- other methods are set to read only -->
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* cn.biaoming.service..*Service.*(..))" advice-ref="txAdvice"/>
</aop:config>
而TransactionInterceptor是这么定义的:
<bean id="articleService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="cn.biaoming.service.ArticleService"/>
<property name="target"><ref local="articleServiceTager"/></property>
<property name="interceptorNames">
<list>
<idref local="articleServiceSecurity"/>
</list>
</property>
</bean>
<bean id="articleServiceSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="businessAccessDecisionManager"/></property>
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource">
<value>
</value>
</property>
</bean>
现在只要把spring2.x 的AOP去掉,TransactionInterceptor就能正常工作,要不就报以下错误
WARN Cglib2AopProxy.doValidateClass(250) | Unable to proxy method [public final java.util.List $Proxy29.getLatestArticle(java.lang.String,int)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
- 21:38
- 浏览 (460)
- 论坛浏览 (1476)
- 评论 (11)
- 分类: java
- 相关推荐
评论
一个类只能被代理一次 acegi 配置你已经代理一次了 或者是你在事物代理的时候
SPRING在做代理的时候 已经指出 代理后的类是 FINAL 了·
用SPRING2.0的方式去配置代理 与AOP 应该可以解决问题
SPRING在做代理的时候 已经指出 代理后的类是 FINAL 了·
用SPRING2.0的方式去配置代理 与AOP 应该可以解决问题
已经找到解决的办法。
<aop:config proxy-target-class="true">
<aop:pointcut id="idempotentOperation1"
expression="execution(* cn.biaoming.service.ArticleService.*(..))" />
<aop:advisor pointcut-ref="idempotentOperation1"
advice-ref="articleServiceSecurity" />
</aop:config>
<aop:config proxy-target-class="true">
<aop:pointcut id="idempotentOperation1"
expression="execution(* cn.biaoming.service.ArticleService.*(..))" />
<aop:advisor pointcut-ref="idempotentOperation1"
advice-ref="articleServiceSecurity" />
</aop:config>
a_method_of_articleServiceSecurity这个是articleService的方法,还是articleServiceSecurity的方法呢?如果是articleServiceSecurity,那和objectDefinitionSource定义的拦截方法有冲突吗?
兄弟,a_method_of_articleServiceSecurity的意思就是“articleServiceSecurity的一个方法”,你得把它替换成实际的方法呀
我试了,在启动tomcat 报以下错误
java.lang.IllegalArgumentException: Unable to locate method [a_method_of_articleServiceSecurity] on bean [articleServiceSecurity]
at org.springframework.aop.config.MethodLocatingFactoryBean.setBeanFactory(MethodLocatingFactoryBean.java:75)
java.lang.IllegalArgumentException: Unable to locate method [a_method_of_articleServiceSecurity] on bean [articleServiceSecurity]
at org.springframework.aop.config.MethodLocatingFactoryBean.setBeanFactory(MethodLocatingFactoryBean.java:75)
其实我只是给出了一种声明的方法,看看是否适合你的情况;声明的内容是否正确就不一定了,可能你得多尝试尝试。
就你在帖子里提到的内容来看,估计需要HibernateSession的地方还是要注入。只是估计,最终得以你试验后的结果为准......
就你在帖子里提到的内容来看,估计需要HibernateSession的地方还是要注入。只是估计,最终得以你试验后的结果为准......
我现在在公司,晚上回去试一下,不过有些疑问,这个的意思是在执行ArticleService的所有方法之前先执行articleServiceSecurityAspect,是这样吗?不过ArticleService需要HibernateSession,注入进来不?还是继续使用来注入呢?
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* cn.biaoming.service..*Service.*(..))" advice-ref="txAdvice"/>
</aop:config>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* cn.biaoming.service..*Service.*(..))" advice-ref="txAdvice"/>
</aop:config>
试试:
以上代码不保证没错~~~
引用
<aop:config>
<aop:aspect id="articleServiceSecurityAspect" ref="articleServiceSecurity">
<aop:before
pointcut="execution(* cn.biaoming.service.ArticleService.*(..))"
method="a_method_of_articleServiceSecurity"/>
</aop:aspect>
</aop:config>
<bean id="articleServiceTager" class="cn.biaoming.service.ArticleServiceTager" />
<aop:aspect id="articleServiceSecurityAspect" ref="articleServiceSecurity">
<aop:before
pointcut="execution(* cn.biaoming.service.ArticleService.*(..))"
method="a_method_of_articleServiceSecurity"/>
</aop:aspect>
</aop:config>
<bean id="articleServiceTager" class="cn.biaoming.service.ArticleServiceTager" />
以上代码不保证没错~~~
现在是用了aop:advice>、<aop:advisor>之后把都给我的方法(运行时)加上了final方法。
楼上的意思是让我尝试articleServiceSecurity也用Spring的<aop:advice>、<aop:advisor>是吗?我也想过这个问题,但是我不知道用哪种方法替换。
楼上的意思是让我尝试articleServiceSecurity也用Spring的<aop:advice>、<aop:advisor>是吗?我也想过这个问题,但是我不知道用哪种方法替换。
- 浏览: 40849 次

- 详细资料
搜索本博客
我的相册
{EADD2367-2334-4234-2434-231181485467}0
共 1 张
共 1 张
链接
- The Tapestry sample applications
- ruby
- Lucene
- Maven 2 简明学习指南(2)
- jsf
- 石头记
- srpingide
- 使用attachment_fu上传
- rails 文件上传
- ruby on rails 实现多文件的上传
- Ruby 多文件上传并写入数据库
- Hibernate Search牛刀小试
- springside分页
- 用Acegi Security来保护Grails应用
- 精通 Grails: 构建您的第一个 Grails 应用程序
- Chinese User Guide
- Rails宝典之第五十二式: 使用Checkbox来更新
- ruby 分页
- ruby 不错的分页
- js效果
- 很多值得看的多线程例子
- web监控
最新评论
-
compass中如何配置分词器 ...
spring配置compass分词器!经过本人多次尝试,以上楼的方法不正确,正确 ...
-- by cslgdxzhangpeng -
在Debian上部署Rails Apac ...
适合我这种新手看.
-- by yangzhihuan -
hibernate usertype 如何 ...
我也了解,确实像楼上说的。现在我想换用jpa,因为他有个@PreRemove @ ...
-- by biaoming -
hibernate usertype 如何 ...
UserType无法得知状态
-- by Quake Wang -
发现一个在线学习groovy的 ...
按照教程,练习了一把,感觉不错。
-- by yf1975






评论排行榜