Problems encountered in SSH AOP learning process ...

Source: Internet
Author: User
Tags aop ssh

First I guarantee that the code will work well before AOP is implemented.
Then learn SSH uses AOP to add permission control before the action method, which is to log the error message.

Explain AOP with XML annotations first
<aop:config proxy-target-class= "true" > <aop:aspect ref= "rightfilter" > <aop:before method= " Rightfilter "pointcut=" Execution (* com.exdoit.action.Main.mainPage ()) "></aop:before> <aop:after method = "Actionafter" pointcut= "Execution (* com.exdoit.action.Main.mainPage ())" ></aop:after> </aop:aspect > </aop:config>

At first the annotation annotation was used, and then the problem was not found Proxy-target-class how the annotation was translated into XML.

Java.lang.NoSuchMethodException: $Proxy ...
The method cannot be found in the proxy object first. The problem is solved.

There are 2 ways to generate proxy objects in spring.

1: Using the proxy in the JDK implementation, our agents must be to implement a proxy interface, proxy objects and the nature of the agent is to achieve a unified interface of two objects

2: The use of cglib to achieve. The proxy object does not need to implement an Agent interface, which is essentially a parent-child relationship between the proxy class and the proxy class.

Proxy-target-class= "True" specifies that the implementation agent is implemented by Cglib.

Workaround (2 kinds): Cancel inheritance com.opensymphony.xwork2.ActionSupport discard <aop:config proxy-target-class= "true" in this method configuration file .... </aop:config>

Continue the AOP permission Control test and report the following error
Cannot proxy target class because CGLIB2 is not available. Add Cglib to the class path or specify proxy interfaces.
No packages added Cglib.jar ... You said you had no bag and you were as noclassdeffounderror as the following tips. What else do you want ADD cglib to the class ... It took half a day to understand that it was less.

... Go on

Nested exception is java.lang.NoClassDefFoundError:Could not initialize class ...

According to the prompts to find the bag is the simple question.

The result is a successful AOP interception, but the action variable has no output ...
such as public String Nextpath, a value cannot be fetched directly using the public declaration (the value can be declared directly by public declaration without AOP). You need to add a get method to the variable:
Public String Getnextpath () {return nextpath;}
When a variable is requested, it turns to find the return value of the variable get method.

It should be an AOP dynamic proxy mechanism that causes public variables to be modified in action-appropriate methods that are not implemented.

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.