There are two types of bean property injection in spring
Constructor injection
<bean id="car"> <constructor-arg index="0" type="java.lang.String" value="Porsche"></constructor-arg> <constructor-arg index="1" type="double" value="2000000"></constructor-arg></bean>
Setter method injection
<bean id="car"> <property name="name" value="jaguar"/> <property name="price" value="500000"/></bean>
Injection of collection attributes
In spring, for collection attributes, special tags can be used to complete the injection.
For example: list set map properties and other collection elements to complete collection attribute injection.
List property injection
If the property is an array type, you can also use list to complete the injection
Set property injection
Map attribute injection
Properties property injection
Java.util.Properties is the implementation class of java.util.Map, and its key and value are both String types.
<props> <prop key="company">nwtxxb</prop> <prop key="price">100000</prop></props>
Summarize
The above is the Spring Bean property injection method introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!