Changes between Version 13 and Version 14 of waue/2011/spring


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

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2011/spring

    v13 v14  
    2020= eclipse 開發環境 =
    2121
    22  * eclipse 安裝套件
    23 
    24 在Eclipse的套件中,安裝AJDT
    25 
    26 {{{
    27 #!text
    28 eclipse->Help->install new software->add->輸入Name: ajdt
    29 URL: http://download.eclipse.org/tools/ajdt/36/dev/update
    30 }}}
    31 其中36指的是Eclipse Helios版本,如果用的是3.4版,請改為34
    32 
    33 安裝SpreingIDE
    34 
    35 {{{
    36 #!text
    37 Name: SpringIDE
    38 URL: http://dist.springframework.org/release/IDE
    39 }}}
    40 
    41  * 建立 Spring 專案
    42 
    43 {{{
    44 #!text
    45 file -> 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
    84 package waue.org;
    85 
    86 public 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
    103 package waue.org;
    104 
    105 import org.springframework.beans.factory.BeanFactory;
    106 import org.springframework.beans.factory.xml.XmlBeanFactory;
    107 import org.springframework.core.io.FileSystemResource;
    108 import org.springframework.core.io.Resource;
    109 
    110 public 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 
    127 run -> "run aspectj/java application"  or "run java application" 皆可
     22[wiki:waue/2011/SpringEclipse 詳見SpringEclipse]
    12823
    12924= spring =
     
    249144IoC 在容器的角度,可以用這麼一句好萊塢名言來代表:"Don't call me, I'll call you." 以程式的術語來說的話,就是「不要向容器要求您所需要的(物件)資源,容器會自動將這些物件給您!」。IoC 要求的是容器不侵入應用程式本身,應用程式本身提供好介面,容器可以透過這些介面將所需的資源注至至程式中,應用程式不向容器主動要求資源,故而不會依賴於容器的元件,應用程式本身不會意識到正被容器使用,可以隨時從容器中脫離轉移而不用作任何的修改,而這個特性正是一些業務邏輯中間件最需要的。
    250145
     146 = Dependency Injection =
     147[wiki:waue/2011/DI 詳見 Dependency Injection ]