| 1 | {{{ |
| 2 | #!html |
| 3 | <div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big> |
| 4 | Spring Eclipse |
| 5 | </big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big> |
| 6 | Spring 3.1 + Eclipse 3.6 |
| 7 | </big></big></div> |
| 8 | }}} |
| 9 | [[PageOutline]] |
| 10 | |
| 11 | * eclipse 安裝套件 |
| 12 | |
| 13 | 在Eclipse的套件中,安裝AJDT |
| 14 | |
| 15 | {{{ |
| 16 | #!text |
| 17 | eclipse->Help->install new software->add->輸入Name: ajdt |
| 18 | URL: http://download.eclipse.org/tools/ajdt/36/dev/update |
| 19 | }}} |
| 20 | 其中36指的是Eclipse Helios版本,如果用的是3.4版,請改為34 |
| 21 | |
| 22 | 安裝SpreingIDE |
| 23 | |
| 24 | {{{ |
| 25 | #!text |
| 26 | Name: SpringIDE |
| 27 | URL: http://dist.springframework.org/release/IDE |
| 28 | }}} |
| 29 | |
| 30 | * 建立 Spring 專案 |
| 31 | |
| 32 | {{{ |
| 33 | #!text |
| 34 | file -> new -> project -> Spring => Spring Project : myFirstSpring |
| 35 | }}} |
| 36 | |
| 37 | * 匯入函式庫 |
| 38 | {{{ |
| 39 | #!text |
| 40 | 右鍵點選 myFirstSpring -> properties -> Java Build Path => Libraries => add External Jars |
| 41 | }}} |
| 42 | |
| 43 | 將 spring 資料夾內的jar 檔加入,<<重要>> 並且將 jakara-commons 的 logging.jar 匯入 (可使用hadoop/lib/ 內的 commons-*.jar) |
| 44 | |
| 45 | * 建立佈署檔 beans-config.xml |
| 46 | |
| 47 | {{{ |
| 48 | #!text |
| 49 | 右鍵點選 myFirstSpring -> new -> others -> XML => XML File -> myFirstSpring , File name = beans-config.xml |
| 50 | }}} |
| 51 | |
| 52 | * beans-config.xml |
| 53 | |
| 54 | {{{ |
| 55 | #!xml |
| 56 | <?xml version="1.0" encoding="UTF-8"?> |
| 57 | <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" |
| 58 | "http://www.springframework.org/dtd/spring-beans.dtd"> |
| 59 | <beans> |
| 60 | <bean id="helloBean" |
| 61 | class="onlyfun.caterpillar.HelloBean"> |
| 62 | <property name="helloWord"> |
| 63 | <value>Hello! Waue!</value> |
| 64 | </property> |
| 65 | </bean> |
| 66 | </beans> |
| 67 | }}} |
| 68 | |
| 69 | * src/waue.org/HelloBean.java |
| 70 | |
| 71 | {{{ |
| 72 | #!java |
| 73 | package waue.org; |
| 74 | |
| 75 | public class HelloBean { |
| 76 | private String helloWord; |
| 77 | |
| 78 | public void setHelloWord(String helloWord) { |
| 79 | this.helloWord = helloWord; |
| 80 | } |
| 81 | public String getHelloWord() { |
| 82 | return helloWord; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | }}} |
| 87 | |
| 88 | * src/waue.org/SpringDemo.java |
| 89 | |
| 90 | {{{ |
| 91 | #!java |
| 92 | package waue.org; |
| 93 | |
| 94 | import org.springframework.beans.factory.BeanFactory; |
| 95 | import org.springframework.beans.factory.xml.XmlBeanFactory; |
| 96 | import org.springframework.core.io.FileSystemResource; |
| 97 | import org.springframework.core.io.Resource; |
| 98 | |
| 99 | public class SpringDemo { |
| 100 | public static void main(String[] args) { |
| 101 | Resource rs = |
| 102 | new FileSystemResource("beans-config.xml"); |
| 103 | BeanFactory factory = |
| 104 | new XmlBeanFactory(rs); |
| 105 | |
| 106 | HelloBean hello = |
| 107 | (HelloBean) factory.getBean("helloBean"); |
| 108 | System.out.println(hello.getHelloWord()); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | }}} |
| 113 | |
| 114 | * 看結果 |
| 115 | |
| 116 | run -> "run aspectj/java application" or "run java application" 皆可 |