Java.lang.NoSuchMethodException:com.sun.proxy. $Proxy 58.list Error Resolution _java

Source: Internet
Author: User
Tags abstract web ssh


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!


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.