Changes between Initial Version and Version 1 of waue/2011/SpringEclipse


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

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2011/SpringEclipse

    v1 v1  
     1{{{
     2#!html
     3<div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big>
     4Spring Eclipse
     5</big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big>
     6Spring 3.1 + Eclipse 3.6
     7</big></big></div>
     8}}}
     9[[PageOutline]]
     10
     11 * eclipse 安裝套件
     12
     13在Eclipse的套件中,安裝AJDT
     14
     15{{{
     16#!text
     17eclipse->Help->install new software->add->輸入Name: ajdt
     18URL: http://download.eclipse.org/tools/ajdt/36/dev/update
     19}}}
     20其中36指的是Eclipse Helios版本,如果用的是3.4版,請改為34
     21
     22安裝SpreingIDE
     23
     24{{{
     25#!text
     26Name: SpringIDE
     27URL: http://dist.springframework.org/release/IDE
     28}}}
     29
     30 * 建立 Spring 專案
     31
     32{{{
     33#!text
     34file -> 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
     73package waue.org;
     74
     75public 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
     92package waue.org;
     93
     94import org.springframework.beans.factory.BeanFactory;
     95import org.springframework.beans.factory.xml.XmlBeanFactory;
     96import org.springframework.core.io.FileSystemResource;
     97import org.springframework.core.io.Resource;
     98
     99public 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
     116run -> "run aspectj/java application"  or "run java application" 皆可