java.lang.NoSuchMethodException: com.sun.proxy.$Proxy58.list error resolution

  • 2020-05-19 04:55:17
  • OfStack

java.lang.NoSuchMethodException: com.sun.proxy.$Proxy58.list error resolution

Playing SSH with web will always have something unexpected to do with exception, and there are many things that you may not be careful about or have done carelessly. Therefore, the solution will be different, others appear abnormal solution may be invalid for you, just like the above I reported abnormal 1, baidu many, many times, the answer to me is nothing more than to add a sentence on aop, but I am very sorry, I added to the invalid! So the same sentence, for their own abnormal, or to solve their own.

First of all, explain 1 below, the ssh structure of my exercise and the reason for the abnormal report.

struts2.2 + hibernate4.2 + spring4.0, container room tomcat7.0. In Action, I wrote a base class BaseAction, which inherits ActionSupport and implements 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 each component in Action only needs to tell BaseAction what generics it wants to implement, and then only needs to complete its own logic. This is a basic and easily thought of solution for each Action to implement ActionSupport.

Then, in each Action, the service component is called to do its job. In each Action, the @Component (" departmentAction ") and @Scope (" prototype ") annotations are used, but in exercise 1, an Java.lang.NoSuchMethodException: com.sun.proxy.$Proxy58.list () exception is found.

BaseAction is abstract, it doesn't make sense to put @Transactional on it,

As for @Transactional, it is managed by spring, and objects managed by spring need to generate proxies. However, for an abstract class, new cannot become an object, and only the concrete implementation class of an abstract class can be represented by spring.

So, get rid of BaseAction at sign Transactional, and that's the reason for this problem.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: