spring

Spring最重要的部分是IoC Container,它的作用是配置和管理Java对象的生命周期。

反转控制和依赖注入

// Interface HelloWorld
public interface HelloWorld {
    public void sayHello();
}
 
// Class implements HelloWorld
public class SpringHelloWorld implements HelloWorld {
   public void sayHello()  {
           System.out.println("Spring say Hello!");
   }
}
 
// Other class implements HelloWorld
public class StrutsHelloWorld implements HelloWorld {
   public void sayHello()  {
           System.out.println("Struts say Hello!");
   }
}

// And Service class
public class HelloWorldService {
    
     // Field type HelloWorld
     private HelloWorld helloWorld;
    
     // Constructor HelloWorldService
     // It initializes the values for the field 'helloWorld'
     public HelloWorldService()  {
           this.helloWorld = new StrutsHelloWorld();
     }
}

 

 

 

 

 

 

 

 

 

 

 

参考网址:http://www.yiibai.com/spring/spring-tutorial-for-beginners.html#

posted @ 2018-02-03 10:23  牧 天  阅读(107)  评论(0)    收藏  举报