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