<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!--lazy-init Delay loading defaults to false After container initialization, the instance will be constructed if true If I get it bean Only when it's constructed--> <!--scope Scope is used to control the bean The default generation mechanism of is singleton Single interest mode has only one instance in the whole container--> <bean id="user" class="com.java12.spring.demo.User" lazy-init="true" scope="prototype" > <property name="id" value="1"></property> <property name="name" value="tom"></property> </bean> <util:list id="bo"> <value>this is java</value> <value>java core</value> <value>java actual combat</value> </util:list> <!--For sets list Property injection method--> <bean id="bookstore" class="com.java12.spring.entity.BookStop" p:id="123" p:books-ref="bo"></bean> <!--For sets set Attribute injection list And set The way is universal--> <bean id="math" class="com.java12.spring.entity.Math"> <property name="name" value="Prime number"></property> <property name="nums"> <set> <value>1</value> <value>5</value> <value>10</value> <value>3</value> </set> </property> </bean> <!--For sets map Attribute injection--> <bean id="person" class="com.java12.spring.entity.Person"> <property name="age" value="18"></property> <property name="idCards"> <map> <entry key="2121613213" value="213213213"></entry> <entry key="54215" value="4564652313"></entry> </map> </property> </bean> <!--Constructor injection inject based on the index of the constructor (unable to confirm whether the injected value is what you want)--> <bean id="construct" class="com.java12.spring.entity.Contruct"> <constructor-arg index="0" value="101"></constructor-arg> <constructor-arg index="1" value="tom"></constructor-arg> <constructor-arg index="2" value="10.2"></constructor-arg> </bean> <!--Name the constructor's settings--> <bean id="con" class="com.java12.spring.entity.Contruct"> <constructor-arg name="id" value="101"></constructor-arg> <constructor-arg name="name" value="guo"></constructor-arg> <constructor-arg name="weight" value="91.5"></constructor-arg> </bean> <!--Array form--> <bean id="arr" class="com.java12.spring.entity.Arrays" p:id="10" p:arr="abc,asd,dsa"></bean> </beans>
Configuring various properties of bean s in xml
id="xxx" spring obtains instances by id
Class = "full path of class" spring creates an instance based on class path reflection
Lazy init = "true" delay loading the instance creation time of the specified class is false by default. Create the class when loading the configuration file scope="prototype" scope is used to control the generation mechanism of bean s in the container. By default, the singleton singleton mode has only one instance in the whole container (the benefit of singleton is memory saving)
< util: list > < util: list > < util: Map > < util: Map > use the util tag to assign values to reference objects
<map> Injection of map set </map>
< constructor Arg index = "0" value = "101" > < constructor Arg name = "Id" value = "101" >