parent
36b26d2da9
commit
74a98e9d10
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="lab" class="com.ssm.di.xml.Lab">
|
||||
<property name="labId" value="101"/>
|
||||
<property name="labName" value="计算机实验室"/>
|
||||
<property name="location" value="A302"/>
|
||||
<property name="capacity" value="40"/>
|
||||
<property name="status" value="可用"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@ -0,0 +1,14 @@
|
||||
package com.ssm.di.xml;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class TestDI {
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-di.xml");
|
||||
// 终极写法:不指定类型,直接强转,彻底解决类型不匹配
|
||||
Object obj = ac.getBean("lab");
|
||||
System.out.println(obj);
|
||||
((ClassPathXmlApplicationContext) ac).close();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue