Spring Series "2" Application setter injection to implement bean injection

Source: Internet
Author: User

 package   cn.com.xf;  public  class   User { private   String name;  private  int   age;  private   String remark;  //Getter/setter method of omitting properties 
@Override public String toString () { return "User [n Ame= "+ name +", age= "+ Age +", remark= "+ remark +"] ";
 Packagecn.com.xf; Public classUserutil {Privateuser User;  PublicUser GetUser () {returnuser; }     Public voidsetUser (user user) { This. user =user; }     Public BooleanIsUser () {if(User! =NULL) {            return true; } Else {            return false; }    }}
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
<!--Note that the following P-tags are used--xmlns:p= "http://www.springframework.org/schema/p"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "> <BeanID= "User"class= "Cn.com.xf.User"P:name= "Jikoy"P:age= "+"P:remark= "This is remark"></Bean> <BeanID= "Userutil"class= "Cn.com.xf.UserUtil"> < Propertyname= "User"ref= "User"></ Property> </Bean></Beans>

The following is a test class: All code pro-test pass.

 Packagecn.com.xf;ImportOrg.springframework.context.ConfigurableApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classTest { Public Static voidMain (string[] args) {
The ApplicationContext interface does not provide a shutdown method, and Eclipse prompts it to change its sub-interface configurableapplicationcontext ctx=NewClasspathxmlapplicationcontext ("Applicationcontext.xml"); User User= (user) Ctx.getbean ("user")); Ctx.close (); SYSTEM.OUT.PRINTLN (user); }}

Spring Series "2" Application setter injection to implement bean injection

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.