java.lang.NoSuchMethodException: com.sun.proxy.$Proxy58.list error solution
There are always some unexpected exceptions when playing SSH on the web. There are many things that you are not careful or careless. Therefore, the solutions will be different. The solutions that others have encountered may be invalid for you. Just like the exception I reported above, I have been using Baidu many times, and the answer I gave me is nothing more than adding a sentence to AOP, but I am very sorry, I added it to the invalid! So the same thing is true, you still have to solve your own abnormality.
First, let me explain the ssh structure and the reasons for the exception in my practice this time.
The framework-type struts2.2+hibernate4.2+spring4.0, container room tomcat7.0. In Action, I wrote a base class BaseAction, inherited ActionSupport, and implemented 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 this is that the corresponding Action of each component only needs to tell BaseAction the generics to implement, and then only needs to complete its own logic. For each Action to implement ActionSupport, this is a basic and easy-to-think solution.
Then, in each Action, the service component is called to implement its own functions. In each Action, @Component("departmentAction") and @Scope("prototype") annotations are used. However, once you practice the test, a Java.lang.NoSuchMethodException: com.sun.proxy.$Proxy58.list() exception will appear. After checking, it is found that the reason is:
BaseAction is abstract, it doesn't make sense to add @Transactional to it.
@Transactional is managed by spring. The objects managed by spring must be generated as agents. For an abstract class, it cannot be new into an object. Only the concrete implementation class of an abstract class may be proxyed by spring.
Therefore, removing the @Transactional on BaseAction is the reason for this question.
Thank you for reading, I hope it can help you. Thank you for your support for this site!