In Java if no constructors are written in a class, there is an argument-free constructor, as follows:
public class Children {private string Name;private string Address;public string GetName () {return name;} public void SetName (String name) {this.name = name;} Public String getaddress () {return address;} public void setaddress (String address) {this.address = address;}}
The above code is equivalent to the following:
public class Children {private string Name;private string Address;public Children () {}public string getName () {return name ;} public void SetName (String name) {this.name = name;} Public String getaddress () {return address;} public void setaddress (String address) {this.address = address;}}
But if you specify a constructor that has a parameter, the parameterless constructor ceases to exist:
So in the spring configuration, the following configuration is wrong:
<bean id= "Children" class= "Com.wc82.Children" > <property name= "Address" value= "Stresst" > </property> <property name= "name" value= "Nick" ></property> </bean>
The above configuration is similar to the following:
Children c=new Children () C.setname ("Nick"); C.setaddress ("Stresst");
However, the default construction method no longer exists, so it will be an error, can be changed to the following configuration:
<bean id= "Children" class= "Com.wc82.Children" > <constructor-arg value= "1111" /> <constructor-arg value= "" /> </bean>
Default constructors in Java