17_8_9 Spring Injection

Source: Internet
Author: User

1 Spring Bean Attribute injection: The method of constructing the injected property:
<!-- 第一种:构造方法的方式 --><bean id="car" class="cn.itcast.spring.demo4.Car"> <constructor-arg name="name" value="保时捷"/> <constructor-arg name="price" value="1000000"/> </bean>
The methods of the Set method inject properties:
<!-- 第二种:set 方法的方式 --><bean id="car2" class="cn.itcast.spring.demo4.Car2"> <property name="name" value="奇瑞 QQ"/> <property name="price" value="40000"/> </bean>
2 Spring Attribute injection: Injection of the object type:
<bean id="person" class="cn.itcast.spring.demo4.Person">    <property name="name" value="会希"/> <property name="car2" ref="car2"/></bean>
3 Injecting complex types:
<BeanId="Collectionbean"class="Cn.itcast.spring.demo5.CollectionBean" ><!--property of array type--//Can save<List></List><PropertyName="Arrs" ><List><Value> will hope</Value><Value> Crown</Value><Value> Day One</Value></List></Property><!--inject data into the List collection--<PropertyName="List" ><List><Value> Hibiscus</Value><Value> like flowers</Value><Value> Fengjie</Value></List></Property><!--injection Map Collection--<PropertyName="Map" ><Map><Entrykey="AAA"Value="111"/><Entrykey="BBB"Value="222"/><Entrykey="CCC"Value="333"/></Map></Property><!--Properties Injection---<name= "properties" > << Span class= "Hljs-name" >props> <prop  Key= "username" >root</prop> Span class= "Hljs-tag" ><prop key= " Password ">123</prop> </props></property> </BEAN>          
4. Factory method Creation Bean:5 introduction of external properties file
一种方式:<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties"/></bean>二种方式:<context:property-placeholder location="classpath:jdbc.properties"/>

17_8_9 Spring 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.