@Required comment The setter method applied to the Bean property, which indicates that the affected bean properties must be placed in the XML configuration file at configuration time, or the container throws a Beaninitializationexception exception.
Java
Public classStudent {PrivateInteger age; PrivateString name; @Required Public voidsetage (Integer age) { This. Age =Age ; } PublicInteger getage () {returnAge ; } @Required Public voidsetName (String name) { This. Name =name; } PublicString GetName () {returnname; }}
Will throw an exception to the Beans.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-3.0.xsd "> <Context:annotation-config/> <!--Definition for student Bean - <BeanID= "Student"class= "Com.tutorialspoint.Student"> < Propertyname= "Name"value= "Zara" /> <!--try without passing age and check the result - <!--Property name= "Age" value= " One" - </Bean></Beans>
Beans.xml that do not throw exceptions
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-3.0.xsd "> <Context:annotation-config/> <!--Definition for student Bean - <BeanID= "Student"class= "Com.tutorialspoint.Student"> < Propertyname= "Name"value= "Zara" /> < Propertyname= "Age"value= "One"/> </Bean></Beans>
@Required comment The setter method applied to the Bean property, which indicates that the affected bean properties must be placed in the XML configuration file at configuration time, or the container throws a Beaninitializationexception exception.