Spring安装与入门

1. Spring组成

 

  • Inversion of Control (IoC)
  • Aspect Oriented Programming (AOP)
  • Abstract Service

2. Spring下载

http://www.springsource.com/download/community?sid=1212680

3. Spring实例

EricTest.java

package erictest;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class EricTest {
    public static void main(String argv[]) {
        ApplicationContext ctx = new FileSystemXmlApplicationContext("src/ericspring.xml");
        ShowMessage sm = (ShowMessage)ctx.getBean("ericBean");
        sm.show();
    }
}



ShowMessage.java

package erictest;

public class ShowMessage {

    private String message;

    public void setMessage(String message){
           this.message = message;
    }
   
    public String getMessage(){
           return this.message;
    }

    public void show(){
           System.out.print("Spring Test Message: " + getMessage());
    }
}

 

ericspring.xml

package erictest;

<?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 = "ericBean" class="erictest.ShowMessage">
       <property name="message">
           <value>Says Hello Spring!</value>
       </property>
    </bean>
</beans>


运行即可显示结果

Spring Test Message: Says Hello Spring!

posted @ 2011-07-11 23:27  Crazy Eric  阅读(2643)  评论(0编辑  收藏  举报