The parameters of the Controller method in spring note 1:MVN cannot be nested classes (inner classes).

Source: Internet
Author: User

Recently do spring development, personally think, controller and client JS communication when the parameter class passed only a certain number of methods, in order to reduce the impact on other functions, to define the parameter class as the Controller class

Nested classes (inner classes). But practice finds No.

The system will error:

Servlet.service () for Servlets [Kingkoo] in the context with path [] threw exception [Request processing failed; nested Excepti On are org.springframework.beans.BeanInstantiationException:Failed to instantiate [ Com.itl.wms.mvc.systemsetting.poqcsettingcontroller$queryparameter]: No default constructor found; Nested exception is java.lang.NoSuchMethodException: ***************controller$ nested class .<init> ()] With Root cause
Java.lang.NoSuchMethodException:com.itl.wms.mvc.systemsetting. controller$ Nested class .<init> ()

Tip the nested class does not have a constructor for empty arguments. Although I have defined an empty constructor for a class.

Because spring looks for a constructor for a parameter type, it indicates the constructor to find an empty argument:

Return Instantiateclass (Clazz.getdeclaredconstructor ());  Org.springframework.beans.BeanUtils.instantiateClass (beanutils.java:104)
However, inside Java, a nested class is a constructor that has no empty arguments:
public class App {

Public class Nest
{
Public Nest () {}

}

public static void Main (string[] args) throws Exception {

Nestclassconstrunct ();
}

Private static void Nestclassconstrunct ()
{
Java.lang.Class c= Nest.class;
Constructor<?>[] cc= c.getconstructors ();
Parameter[] p;
for (int i = 0; i < cc.length; i++) {
System.out.println (Cc[i].tostring ());
P=cc[i].getparameters ();
for (int j = 0; J < P.length; J + +) {
System.out.println (P[j].getname () + ":" +p[j].getparameterizedtype (). toString ());
}
}
}

Output:

Public App$nest (APP)
Arg0:class App

So, you can only move the parameter class into a specified package.

Please correct the master.

The parameters of the Controller method in spring note 1:MVN cannot be nested classes (inner classes).

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.