把spring.xml放在类路径底下
id:是这个bean的名字,不能重复,class全类名,
反射创建对象
<bean id="bean名字" class="全类名">
<***注入属性***>
<property name="id" value="1"></property>
<property name="name" value="aaa"></property>
<property name="age" value="2"></property>
</bean>
public static void main (String []args){
//1.创建Spring容器
可以从硬盘找xml文件就是File开头的类
new ClassPathXmlApplicationContext("xml地址");
//2.从容器中取到你的想要的对象(bean)
Class...Context.getBean("bean名字");
}
<bean id="name" class="class">
<property name="id" value="1"></property>
<property name="name" value="aaa"></property>
<property name="age" value="2"></property>
</bean>
new ClassPathxmlApplicationContext("xml.地址");
Class... Context.getBean("Bean-name")
<bean id="" class="">
<property name="" value=""></property>
<property name="" value=""></property>
<prpperty name="" value=""></property>
</bean>
new ClassPathxmlApplicationContext("");
Class... Context.getBean();
bean之间的引用
<bean id="car1" class="com.iotek.Car">
<property name="name" value="三轮车"></property>
<property name="speed" value="50km"><property>
</bean>
<bean id="person3" class="com.iotek.Person">
<property name="car" ref="car1"></property>
</bean>
配置集合list和map等
<bean id="car1" calss="">
<property name="" value="car2"></property>
<property name="" value=""></property>
</bean>
<bean id="car2" calss="">
<property name="" value=""></property>
<property name="" value=""></property>
</bean>
<bean id="" class="">
<property name="">
<list>或<set>
<ref bean="car1"> </ref>
<ref bean="car2"> </ref
</list></set>
</property>
</bean>
map
<bean id="" calss="">
<property name="">
<map>
<entry key="1" value-ref="car2"></entry>
<entry key="2" value-ref="car3"></entry>
</map>
</property>
</bean>