`
biaoming
  • 浏览: 266547 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

acegi TransactionInterceptor遇到spring2.x

    博客分类:
  • java
阅读更多
一直使用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.

分享到:
评论
11 楼 imp9527 2008-03-29  
  一个类只能被代理一次 acegi 配置你已经代理一次了 或者是你在事物代理的时候
     SPRING在做代理的时候 已经指出 代理后的类是 FINAL 了·
         用SPRING2.0的方式去配置代理 与AOP 应该可以解决问题
10 楼 biaoming 2008-03-15  
已经找到解决的办法。

<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>
9 楼 biaoming 2008-03-13  
没有有知道了吗?
8 楼 biaoming 2008-03-12  
a_method_of_articleServiceSecurity这个是articleService的方法,还是articleServiceSecurity的方法呢?如果是articleServiceSecurity,那和objectDefinitionSource定义的拦截方法有冲突吗?
7 楼 movingboy 2008-03-11  
兄弟,a_method_of_articleServiceSecurity的意思就是“articleServiceSecurity的一个方法”,你得把它替换成实际的方法呀
6 楼 biaoming 2008-03-11  
我试了,在启动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)
5 楼 movingboy 2008-03-11  
其实我只是给出了一种声明的方法,看看是否适合你的情况;声明的内容是否正确就不一定了,可能你得多尝试尝试。
就你在帖子里提到的内容来看,估计需要HibernateSession的地方还是要注入。只是估计,最终得以你试验后的结果为准......
4 楼 biaoming 2008-03-11  
我现在在公司,晚上回去试一下,不过有些疑问,这个的意思是在执行ArticleService的所有方法之前先执行articleServiceSecurityAspect,是这样吗?不过ArticleService需要HibernateSession,注入进来不?还是继续使用来注入呢?
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* cn.biaoming.service..*Service.*(..))" advice-ref="txAdvice"/>
</aop:config>
3 楼 movingboy 2008-03-11  
试试:

引用
<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" />


以上代码不保证没错~~~
2 楼 biaoming 2008-03-11  
现在是用了aop:advice>、<aop:advisor>之后把都给我的方法(运行时)加上了final方法。
楼上的意思是让我尝试articleServiceSecurity也用Spring的<aop:advice>、<aop:advisor>是吗?我也想过这个问题,但是我不知道用哪种方法替换。
1 楼 movingboy 2008-03-10  
问题在于使用ProxyFactoryBean时,它代理的类不能有final方法;如果纯粹地使用Spring的<aop:advice>、<aop:advisor>则不会有问题。所以你最好尝试一下修改articleServiceSecurity这个bean的声明方式,看看能否使用后者

相关推荐

Global site tag (gtag.js) - Google Analytics