• Spring 接口代理 类代理


    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!

     

  • 相关阅读:
    Java8 lambda表达式语法 1
    Spring WebMVC 4.1返回json时 406(Not Acceptable)
    上传 第三方jar包 nexus
    Nexus 使用配置
    Nexus 安装 使用说明
    mysql 常用命令
    JedisPoolConfig配置
    tomcat 管理端 安全措施
    Java ReentrantLock和synchronized两种锁定机制的对比
    spring 在web容器启动时执行初始化方法
  • 原文地址:https://www.cnblogs.com/rocky-fang/p/5322724.html
Copyright © 2020-2023  润新知