Version 2 (modified by waue, 13 years ago) (diff) |
---|
Spring Eclipse
Spring 3.1 + Eclipse 3.6
- eclipse 安裝套件
在Eclipse的套件中,安裝AJDT
eclipse->Help->install new software->add->輸入Name: ajdt URL: http://download.eclipse.org/tools/ajdt/36/dev/update
其中36指的是Eclipse Helios版本,如果用的是3.4版,請改為34
安裝SpreingIDE
Name: SpringIDE URL: http://dist.springframework.org/release/IDE
- 建立 Spring 專案
file -> new -> project -> Spring => Spring Project : myFirstSpring
- 匯入函式庫
右鍵點選 myFirstSpring -> properties -> Java Build Path => Libraries => add External Jars
將 spring 資料夾內的jar 檔加入,<<重要>> 並且將 jakara-commons 的 logging.jar 匯入 (可使用hadoop/lib/ 內的 commons-*.jar)
- 建立佈署檔 beans-config.xml
右鍵點選 myFirstSpring -> new -> others -> XML => XML File -> myFirstSpring , File name = beans-config.xml
- beans-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloBean" class="onlyfun.caterpillar.HelloBean"> <property name="helloWord"> <value>Hello! Waue!</value> </property> </bean> </beans>
- src/waue.org/HelloBean.java
package waue.org; public class HelloBean { private String helloWord; public void setHelloWord(String helloWord) { this.helloWord = helloWord; } public String getHelloWord() { return helloWord; } }
- src/waue.org/SpringDemo.java
package waue.org; 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 SpringDemo { public static void main(String[] args) { Resource rs = new FileSystemResource("beans-config.xml"); BeanFactory factory = new XmlBeanFactory(rs); HelloBean hello = (HelloBean) factory.getBean("helloBean"); System.out.println(hello.getHelloWord()); } }
- 看結果
run -> "run aspectj/java application" or "run java application" 皆可
Attachments (1)
- 3.png (176.2 KB) - added by waue 13 years ago.
Download all attachments as: .zip