Code from Spring in Action

Source: Internet
Author: User

1. Typical Spring configuration file

<? XML version= "1.0" encoding= "UTF-8" ?> <  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 "  ></beans>

2.Spring Beans Configuration

<BeanID= "User"class= "Com.zbwang.demo.User"/><BeanID= "User"class= "Com.zbwang.demo.User">    <Constructor-argvalue= "Ten"/></Bean><BeanID= "User"class= "Com.zbwang.demo.User">    <Constructor-argvalue= "Ten"/>    <Constructor-argref= "Sonnet"/></Bean><BeanID= "Stage"class= "Com.zbwang.demo.Stage"Factory-method= "GetInstance"/><BeanID= "User"class= "Com.zbwang.demo.User"Scope= "Prototype"/><BeanID= "User"class= "Com.zbwang.demo.User"Init-method= "TurnOn"Destroy-method= "Turnoff"/>

Initializingbean declares the Afterpropertiesset method as the initialization method, and Disposablebean declares the Destroy method, the disadvantage of using these interfaces is that the bean and spring APIs produce a coupling Unless you develop a bean that is obviously used in a spring container. You can declare initialization and destroy methods for all beans:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 "Default-init-method= "TurnOn"Default-destroy-method= "Turnoff"></Beans>

Set injection

<BeanID= "User"class= "Com.zbwang.demo.User">    < Propertyname= "username"value= "Focusahaha"/>    < Propertyname= "Age"value= " the"/>
< Property name= "Neigbor" ref= "melon"/>
</Bean>

Internal Bean

<BeanID= "User"class= "Com.zbwang.demo.User">    < Propertyname= "Date">        <Beanclass= "Com.zbwang.demo.Date"/>    </ Property>    </Bean>

P namespace

<?XML version= "1.0" encoding= "UTF-8"?>  <Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><BeanID= "User"class= "Com.zbwang.demo.User"P:username= "Focusahaha"P:age= " the"P:neigbor-ref= "Melon"/></Beans>

Code from Spring in Action

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.