A detailed description of the bean injection parameters in spring

Source: Internet
Author: User
Tags cdata xml parser

Literal value
Generally refers to the values represented by the available strings, which can be injected through the <value> element tags. By default, the base data type and its enclosing class, string, and so on, can be injected in a literal manner, and the spring container internally provides an editor for the literal value, which converts the literal value represented by a string to the corresponding type of the internal variable.
Configuration information:
<bean id= "Car" class= "Com.luxl.domain.Car" >
<property name= "Maxspeed" >
<property name= "Brand" >
<value><! [Cdata[Hongqi &CA72]]></value>
Note: Because the Brand property value contains a special symbol for XML, it is intentionally added an XML special handling tag outside the property value <! [Cdata[]]>, the effect is to have the XML parser treat the string in the tag as plain text, preventing some strings from damaging the XML format.

referencing other beans
Beans defined in the Spring IOC container can interact with each other. The IOC container acts as a medium.
Citation: <ref bean= "Car" ></ref>
The <ref> element can refer to other beans in the container through the following 3 properties.
1) Bean: A bean that can reference the same container or parent container;
2) Local: Only the beans defined in the same configuration file can be referenced, and the legitimacy is automatically checked.
3) Parent: references The bean in the parent container, such as <ref parent= "car" > Configuration description Car's bean is the bean in the parent container.

Collection type Properties
(1) List: Configuration information:
<property name= "Favorites" >
(2) Map: Configuration information:
<property name= "Jobs" >
<value> Bye Customer </value>
(3) Property: Configuration information:
<property name= "mails" >
<prop key= "Jobmail" >www.baidu.com</prop>

Automatic Assembly
The Default-autowire property in the     <beans> element tag can be configured with global auto-match, the default value is no, which means no automatic assembly is enabled, and several other optional configuration values are byname, Bytype, Constructor and AutoDetect. Automated assembly strategies defined in <beans> can be overridden by the automated assembly strategy of <bean>.

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.