Spring interface proxy, spring interface proxy

Source: Internet
Author: User

Spring interface proxy, spring interface proxy

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 at 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 shoshould change its Proxy Way, as follows:

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

    

Then @ RequiresPermissions Annotation works!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.