Summary of bean injection values in Spring 3

Source: Internet
Author: User

There are three methods:

    • Normal way
    • Shortcut
    • "P" Schema

Suppose we have such a bean:

 
Public class filenamegenerator {private string name; private string type; Public String getname () {return name;} public void setname (string name) {This. name = Name;} Public String GetType () {return type;} public void settype (string type) {This. type = type ;}}

1. normal way
<Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id = "filenamegenerator" class = "com. mkyong. common. filenamegenerator "> <property name =" name "> <value> mkyong </value> </property> <property name =" type "> <value> TXT </value> </property> </bean> </beans>

2. Shortcut
<Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id = "filenamegenerator" class = "com. mkyong. common. filenamegenerator "> <property name =" name "value =" mkyong "/> <property name =" type "value =" TXT "/> </bean> </beans>

3. "P" schema
<Beans xmlns = "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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id = "filenamegenerator" class = "com. mkyong. common. filenamegenerator "P: Name =" mkyong "P: TYPE =" TXT "/> </beans>

The third method needs to be added: Xmlns: P = "http://www.springframework.org/schema/p

You can choose either of the three methods, depending on your preferences.

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.