1、下载需要的jar包
2、Spring中IOC的基本使用,在Eclipse中创建一个java项目
a、导入Spring相关的包以及common-loggin包(在项目上右键属性,java构建路径->库->添加外部jar(x))
b、创建Person类型
package springproject.demo;
public class Person {
private String mName;
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
}
c、创建Main文件
package springproject.demo;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
public class Main {
public static void main(String[] args) {
Resource resource = new FileSystemResource("bean.xml");
BeanFactory factory = new XmlBeanFactory(resource);
Person mybean = (Person) factory.getBean("person1");
System.out.print(mybean.getName());
}
}
d、创建Beans配置文件。在配置文件中通过控制反转创建Person对像。
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">
运行Main文件,就会输出xx文字了。