一:spring入门
1:新建java project,在项目名字下面建立lib,
、
2:在applicationContext.xml文件中配置
<?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="SpringHello" class="com.wth.cn.SpringHello">(注意此处为类全名,是通过控制反转的方式创建对象的,所以必须在该类(SpringHello)中要有无参构造方法)
<property name="name2" value="小猫"></property>
</bean>
</beans>
3:在Main类中写
public static void main(String[] args){
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SpringHello springHello = (SpringHello)ctx.getBean("SpringHello");
System.out.println(springHello.getName2());
// SpringHello springHello=new SpringHello();
// springHello.setName("小狗");
// System.out.println(springHello.getName());
}
二:IOC
1:IOC容器作用
原文:https://www.cnblogs.com/wth21-1314/p/10327876.html