Spring2.5 Learning 2.3_ How to inject basic types

Source: Internet
Author: User

Before learning how to inject dependent objects, now learn how to inject basic types.


Personservicebean.java

Package Xjj.service.impl;import Xjj.dao.persondao;import Xjj.service.personservice;public class PersonServiceBean Implements Personservice {private Persondao persondao;private String name;private integer id;public integer getId () {Retu RN ID;} public void SetId (Integer id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public Personservicebean () {}public void Setpersondao (Persondao persondao) {This.persondao = Persondao;} Public Persondao Getpersondao () {return persondao;} @Overridepublic void Save () {System.out.println ("Name:" +name+ "\ n" + "ID:" +id);p Ersondao.add ();}  }


Beans.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans"       Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"       xsi:schemalocation= "http://www.springframework.org/ Schema/beans           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd ">          <bean id=" Personservice "class=" Xjj.service.impl.PersonServiceBean ">          <property name=" Persondao "><bean class = "Xjj.dao.impl.PersonDaoBean"/>                    </property>          <property name= "name" value= "XJJ" ></ property>          <property name= "id" value= "></property>"          </bean></beans>


Springtest.java

Package Junit.test;import Org.junit.beforeclass;import Org.junit.test;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;import Xjj.service.personservice;public Class springtest {@BeforeClasspublic static void Setupbeforeclass () throws Exception {} @Test public void instancespring () { ApplicationContext CTX = new Classpathxmlapplicationcontext ("Beans.xml"); Personservice Personservice = (personservice) ctx.getbean ("Personservice");p Ersonservice.save ();}}


Results:



Spring2.5 Learning 2.3_ How to inject basic types

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.