Changes between Version 11 and Version 12 of waue/2011/spring


Ignore:
Timestamp:
Aug 25, 2011, 5:10:12 PM (13 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2011/spring

    v11 v12  
    55Spring 學習
    66</big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big>
    7 
     7Spring 3.1.0 + eclipse 3.6
    88</big></big></div>
    99}}}
     
    1818
    1919
    20 == eclipse 開發環境 ==
    21 
    22 1.在Eclipse的套件中,安裝AJDT
     20= eclipse 開發環境 =
     21
     22 * eclipse 安裝套件
     23
     24在Eclipse的套件中,安裝AJDT
     25
    2326{{{
    2427#!text
     
    2831其中36指的是Eclipse Helios版本,如果用的是3.4版,請改為34
    2932
    30 
    31 2.安裝SpreingIDE,步驟同上
     33安裝SpreingIDE
     34
    3235{{{
    3336#!text
     
    3538URL: http://dist.springframework.org/release/IDE
    3639}}}
     40
     41 * 建立 Spring 專案
     42
     43{{{
     44#!text
     45file -> new -> project -> Spring => Spring Project : myFirstSpring
     46}}}
     47
     48 * 匯入函式庫
     49{{{
     50#!text
     51右鍵點選 myFirstSpring -> properties -> Java Build Path => Libraries => add External Jars
     52}}}
     53
     54將 spring 資料夾內的jar 檔加入,<<重要>> 並且將 jakara-commons 的 logging.jar 匯入 (可使用hadoop/lib/ 內的 commons-*.jar)
     55
     56 * 建立佈署檔 beans-config.xml
     57
     58{{{
     59#!text
     60右鍵點選 myFirstSpring -> new -> others -> XML => XML File -> myFirstSpring , File name = beans-config.xml
     61}}}
     62
     63 * beans-config.xml
     64
     65{{{
     66#!xml
     67<?xml version="1.0" encoding="UTF-8"?>
     68<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
     69  "http://www.springframework.org/dtd/spring-beans.dtd">
     70<beans>
     71    <bean id="helloBean"
     72    class="onlyfun.caterpillar.HelloBean">
     73        <property name="helloWord">
     74            <value>Hello! Waue!</value>
     75        </property>
     76    </bean>
     77</beans>
     78}}}
     79
     80 * src/waue.org/HelloBean.java
     81
     82{{{
     83#!java
     84package waue.org;
     85
     86public class HelloBean {
     87    private String helloWord;
     88   
     89    public void setHelloWord(String helloWord) {
     90        this.helloWord = helloWord;
     91    }
     92    public String getHelloWord() {
     93        return helloWord;
     94    }
     95}
     96
     97}}}
     98
     99 * src/waue.org/SpringDemo.java
     100
     101{{{
     102#!java
     103package waue.org;
     104
     105import org.springframework.beans.factory.BeanFactory;
     106import org.springframework.beans.factory.xml.XmlBeanFactory;
     107import org.springframework.core.io.FileSystemResource;
     108import org.springframework.core.io.Resource;
     109
     110public class SpringDemo {
     111    public static void main(String[] args) {
     112        Resource rs =
     113            new FileSystemResource("beans-config.xml");
     114        BeanFactory factory =
     115            new XmlBeanFactory(rs);
     116       
     117        HelloBean hello =
     118            (HelloBean) factory.getBean("helloBean");
     119        System.out.println(hello.getHelloWord());
     120    }
     121}
     122
     123}}}
     124
     125 * 看結果
     126
     127run -> "run aspectj/java application"  or "run java application" 皆可
     128
    37129= spring =
    38130