Java. Lang. nosuchmethodexception: $ proxy

Source: Internet
Author: User

Today, we encountered such an exception. It turned out to be a proxy for the action, which is in the spring configuration file. Therefore, modification is normal.

 

How to modify it?

1. if you add a proxy, you must use the following methods in the action.

<Property name = "transactionattributes">
<Props>
<Prop key = "find *"> propagation_required, readonly </prop>
<Prop key = "get *"> propagation_required, readonly </prop>
<Prop key = "query *"> propagation_required, readonly </prop>
<Prop key = "*"> propagation_required </prop>
</Props>
</Property>

2. No proxy is configured ..

3. 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>
<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>

First, the annotation is used, and then the annotation of proxy-target-class cannot be found after the problem is found to be converted to XML.

Java. Lang. nosuchmethodexception: $ proxy...
The method cannot be found in the proxy object. The problem is solved.

There are two ways to generate proxy objects in spring,

1: using the proxy implementation in JDK requires that our proxy object must implement a proxy interface. The proxy object and the proxy object are essentially two objects that implement a unified interface.

2: Implemented Using cglib. A proxy interface is not required for the proxy object. The relationship between the proxy class and the proxy class is essentially a parent-child relationship.

Proxy-target-class = "true" indicates that cglib is used to implement proxy.

Solution (2 types ):

1. Cancel inheriting com. opensymphony. xwork2.actionsupport and discard this method.
2. <AOP: config proxy-target-class = "true">... </AOP: config> in the configuration file
The following error is reported when you continue the AOP permission control test.
Cannot proxy target class because cglib2 is not available. Add cglib to the class path or specify proxy interfaces.
No cglib is added. jar package... if you say no package is available, you are just as prompted by noclassdeffounderror below .. add cglib to the class... it takes only half a day to understand that there are fewer packages.

... Continue

Nested exception is Java. Lang. noclassdeffounderror: cocould not initialize class...

Find the package as prompted. A simple problem.

The running result is successfully implemented by AOP interception, but the action variable does not output the result...
For example, public string nextpath; the value cannot be obtained directly using the public declaration (the value can be directly declared using the public declaration Without AOP). You need to add a get method for the variable:
Public String getnextpath () {return nextpath ;}
When a variable is requested, convert it to the return value of the get method of the variable.

It is estimated that the dynamic proxy mechanism of AOP will prevent the modification of public variables in the method corresponding to the action from being 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.