Spring 接口代理 类代理
2016-03-26 13:14
453 查看
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!
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!
相关文章推荐
- Java中的static关键字解析
- java序列化简单使用
- JAVA 注解入门
- JAVA 内存管理
- java文件重命名
- Java异常:Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion;
- JSp+javaBean开发模式---求和运算
- Java 递归实现格雷码(Gray Code)
- Spring MVC异常处理
- Spring Batch(3): 基本概念(批处理DSL)
- java和Ajax
- spring中的setter方法注入
- 很简单的JAVA反射教程
- java中的几个“区别”总结
- 解决struts2过滤器冲突的简单方法
- Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid property 'xxxx'
- Eclipse常用快捷键总结
- struts2类型转换总结
- ZooKeeper Watch Java API浅析getChildren
- Java 线程池