spring入门
pom文件导包
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
beam.xml
<bean class="类名" id="对象id"/>
<bean class="类名" id="对象id">
<property name="属性名" ref="对象id的引用"/>
</bean>
测试类
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("配置文件");
HR hr = (HR) context.getBean("对象id");
hr.interview();
注入复杂数据类型
<bean class="com.study.entity.ComplexBean" id="complexBean">
<property name="name" value="lisi"/>
<property name="age" value="20"/>
<property name="songs">
<array>
<value>a</value>
<value>b</value>
</array>
</property>
<property name="list">
<list>
<value>aa</value>
<value>bb</value>
</list>
</property>
<property name="set">
<set>
<value>q1</value>
<value>q2</value>
</set>
</property>
<property name="map">
<map>
<entry key="p1">
<value>p11</value>
</entry>
<entry key="p2">
<value>p22</value>
</entry>
</map>
</property>
<property name="prop">
<props>
<prop key="w1">w11</prop>
<prop key="w2">w22</prop>
</props>
</property>
<property name="list1">
<list>
<ref bean="employeeA"></ref>
<ref bean="employeeA1"></ref>
</list>
</property>
<property name="map1">
<map>
<entry key="aa" value-ref="employeeB"/>
<entry key="bb" value-ref="employeeB"/>
</map>
</property>
</bean>