1. 程式人生 > >Spring Freamwork 開發初體驗

Spring Freamwork 開發初體驗

true blog 連接 get 添加 ons xsd 行程 detail

工具
  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");

Spring Freamwork 開發初體驗