工具
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/html
建立工程
new java project
建立lib
手動添加進Spring Freamwork目錄libs下的jar包(暫且所有引入)
referenced Libraries
添加lib包中jar
建立測試類
www.xi.com.Personjava
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.HelloSpringspring
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.xmlapache
<?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
app
下載地址:https://spring.io/tools/sts/all
springsource-tool-suite-3.9.0.RELEASE-e4.6.3-updatesite.zip
這個版本的插件工具,與以前下載的Spring 4.0.4.RELEASE不同了。eclipse
2.No embedded stylesheet
在xml文件窗口打開時點擊運行,會出現這個問題,改爲main文件窗口中執行程序。
ide
3.applicationContext.xml
放在src目錄下,下面的代碼才能找到文件。
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");工具