@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.

Source: Internet
Author: User
Tags tutorialspoint

@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.

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.