声明:本博客只用作学习交流,欢迎讨论
第一步:
第二步:
第三步:
第四步:
第五步:
第六步:
第七步:
在Main下建一个resources文件,并设置为resources root,步骤如上所示:
第八步:
在resources文件夹下建立一个 META-INF包,如上步骤新建一个spring config,取名为applicationconfig.xml
第九步:
写一个Person类需要注入一个name属性:
public class Person {
private String name;
public Person(){
}
public void setName(String name) {
this.name = name;
}
public void sayHello(){
System.out.println("Hello I am " + this.name);
}
}
配置applicationconfig.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 name="person" class="com.cc.springlearn.Person">
<property name="name" value="cc"></property>
</bean>
</beans>
第十步:
使用spring创建对象
第十一步:
大功告成!