首页 > 编程语言 > 详细

Spring 接口代理 类代理

时间:2016-03-26 14:07:05      阅读:197      评论:0      收藏:0      [点我收藏+]

1.Question Description :

   when you use @Transactional annotation and @RequiresPermissions annotation (about shiro) together,

   you will find the @RequiresPermissions annotation donot work, why?

 

2. Explain:

    It‘s caused by the Proxy Mechanism of Spring, because the Spring framework preference for Interface Proxy than Class Proxy,

    the method of the class ExampleServiceImpl was agented several times.

    Let‘s look the two kinds of Interface.

    2.1 @Transactional Annotation:

          It was  based on the Interface Proxy default, so it will produce Proxy Object One just like ExampleServiceImpl$$;

   2.2  @RequiresPermissions :

         It was based on the Interface Proxy default too, but it produces Proxy Object Two based on Proxy Object One just like ExampleServiceImpl$$$$,

         that is a really Class Proxy.

  2.3  when the two kinds of Proxy way exist together,  the Classs Proxy will out of action.

 

3.  Solution:

          we should change its Proxy Way, as follows:

        技术分享

        and the same time, change the Proxy Way of Spring, as follows:

    技术分享

       then @RequiresPermissions Annotation works!

 

 

 

Spring 接口代理 类代理

原文:http://www.cnblogs.com/rocky-fang/p/5322724.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!