工具
eclipse
版本:Neon.3 Release (4.6.3)
Spring Freamwork
版本:4.0.4.RELEASE
下载地址:http://repo.springsource.org/libs-release-local/org/springframework/spring/4.0.4.RELEASE/
commons-logging-1.2-bin
下载地址:http://commons.apache.org/
创建工程
new java project
创建lib
手动添加进Spring Freamwork目录libs下的jar包(暂且全部引入)
referenced Libraries
添加lib包中jar
创建测试类
www.xi.com.Person
package www.xi.com;
public class Person {
String name;
public Person() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "SpringTest [name=" + name + "]";
}
}
www.xi.com.HelloSpring
package www.xi.com;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloSpring {
public static void main(String[] args) {
// Person st = new Person();
// st.setName("Spring");
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
Person p = (Person)ac.getBean("person1");
System.out.println(p);
}
}
创建
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="person1" class="www.xi.com.Person">
<property name="name" value="xixiaohui" />
</bean>
</beans>
问题:
1:Spring Tool Suite™ Downloads
连接地址:在Eclipse上安装Spring Tool Suite
http://blog.csdn.net/yerenyuan_pku/article/details/52787157
下载地址:https://spring.io/tools/sts/all
springsource-tool-suite-3.9.0.RELEASE-e4.6.3-updatesite.zip
这个版本的插件工具,与之前下载的Spring 4.0.4.RELEASE不一样了。
2.No embedded stylesheet
在xml文件窗口打开时点击运行,会出现这个问题,改成main文件窗口中执行程序。
3.applicationContext.xml
放在src目录下,下面的代码才能找到文件。
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");