Java.lang.NoSuchMethodException:com.sun.proxy. $Proxy 58.list Error Resolution
The web ssh always has some unexpected exception, many of which are careless or careless. Therefore, the solution will be different, other people appear to your abnormal solution may be invalid, like the above I reported the exception, Baidu many many times, give me the answer is nothing more than a sentence on AOP, but very sorry, I added to the invalid! So still that sentence, for their own abnormalities, or to solve their own.
First of all, I have to explain the SSH structure of this exercise and the reason for the exception reported.
With the frame-type struts2.2+hibernate4.2+spring4.0, Container Chamber tomcat7.0. In the action, I wrote a base class Baseaction, inherits the Actionsupport, implements the Modeldriven interface, the code is as follows:
----------
@Component
@Transactional
----------
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
private static final long serialVersionUID = 2719688501307297741L;
@Resource(name = "roleServiceImpl")
protected RoleService roleService;
@Resource(name = "departmentService")
protected DepartmentService departmentService;
@Resource(name = "userService")
protected UserService userService;
protected T model;
public BaseAction() {
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
@SuppressWarnings("unchecked")
Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
try {
model = clazz.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public T getModel() {
return model ;
}
}
The advantage of doing this is that each component's action needs to tell Baseaction the generics it wants to implement, and then only need to complete its own logic. For each action to achieve actionsupport, this is a basic and easy to think of the solution.
Then, invoke the service component in each action to implement its own function, using @component ("Departmentaction") in each action, @Scope ("prototype") annotation, but practice a test, The Java.lang.NoSuchMethodException:com.sun.proxy. $Proxy 58.list () exception appears and is detected after checking for the following reasons:
Baseaction is abstract, adding @transactional on top is meaningless,
And @transactional is spring management, spring managed objects to generate agents, and for an abstract class, is not new to object, only one abstract class of the concrete implementation class can be the spring agent.
So, remove the baseaction above @transactional, is the reason why.
Thank you for reading, I hope to help you, thank you for your support for this site!