spring 5.0 从入门到放弃 01

国际惯例  helloWorld奉上


  4.0.0
  com.ruge
  spring
  war
  1.0-SNAPSHOT
  spring Maven Webapp
  http://maven.apache.org
  
    
      junit
      junit
      3.8.1
      test
    
    
    
      commons-logging
      commons-logging
      1.2
    
   
    
      org.springframework
      spring-beans
      5.0.0.RELEASE
    
    
    
      org.springframework
      spring-context
      5.0.0.RELEASE
    
    
    
      org.springframework
      spring-core
      5.0.0.RELEASE
    
    
    
      org.springframework
      spring-expression
      5.0.0.RELEASE
    

  
  
    spring
  


package com.ruge.test;

/**
 * 描述:
 * spring的helloworld
 *
 * @outhor 爱丽丝、如歌
 * @create 2017-11-01 20:50
 */
public class HelloWorld {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public void hello(){
        System.out.println("hello:"+name);
    }
}
package com.ruge.test;

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

/**
 * 描述:
 * main测试类
 *
 * @outhor 爱丽丝、如歌
 * @create 2017-11-01 20:52
 */
public class test {
    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.setName("爱丽丝、如歌");
        //调用方法
        helloWorld.hello();
    }
}

D:\download\tool\jdk\jdk8_64\install\bin\java -Didea.launcher.port=7532 -Didea.launcher.bin.path=D:\download\tool\ide\idea\2016\ideaIU-2016\install\bin -Dfile.encoding=UTF-8 -classpath D:\download\tool\jdk\jdk8_64\install\jre\lib\charsets.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\deploy.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\access-bridge-64.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\cldrdata.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\dnsns.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\jaccess.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\jfxrt.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\localedata.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\nashorn.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunec.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunjce_provider.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunmscapi.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunpkcs11.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\zipfs.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\javaws.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jce.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jfr.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jfxswt.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jsse.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\management-agent.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\plugin.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\resources.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\rt.jar;D:\project_idea\spring\target\classes;D:\download\tool\versionControl\maven\localRepository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-beans\5.0.0.RELEASE\spring-beans-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-context\5.0.0.RELEASE\spring-context-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-aop\5.0.0.RELEASE\spring-aop-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-core\5.0.0.RELEASE\spring-core-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-jcl\5.0.0.RELEASE\spring-jcl-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-expression\5.0.0.RELEASE\spring-expression-5.0.0.RELEASE.jar;D:\download\tool\ide\idea\2016\ideaIU-2016\install\lib\idea_rt.jar com.intellij.rt.execution.application.AppMain com.ruge.test.test
hello:爱丽丝、如歌

Process finished with exit code 0

IOC与DI

  设计原则中好莱坞原则描述到,“别找我们,我们找你”,百度百科上对这点描述是“不要给我们打电话,我们会给你打电话(don‘t call us, we‘ll call you)”这是著名的好莱坞原则。在好莱坞,把简历递交给演艺公司后就只有回家等待。由演艺公司对整个娱乐项的完全控制,演员只能被动式的接受公司的差使,在需要的环节中,完成自己的演出。这一点完美的提现了在IOC身上,IOC所注重的是设计思想上,从一个常规的创建对象的做法,即new一个对象,转变成向IOC容器递交”简历“,被动的等待IOC容器返回资源给你。控制反转即指的是”演艺公司控制演员“,而说到依赖,则是“演员需要公司混饭”,我们所需求的对象,需要依赖容器来获得,这个过程即是依赖注入。本质上IOC和DI是同一思想下不同维度的表现




    
    
        
        
    


package com.ruge.test;

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

/**
 * 描述:
 * main测试类
 *
 * @outhor 爱丽丝、如歌
 * @create 2017-11-01 20:52
 */
public class test {
    public static void main(String[] args) {
        //获取Spring的ApplicationContext配置文件,注入IOC容器中
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("hello");
        //调用方法
        helloWorld.hello();
    }
}

D:\download\tool\jdk\jdk8_64\install\bin\java -Didea.launcher.port=7534 -Didea.launcher.bin.path=D:\download\tool\ide\idea\2016\ideaIU-2016\install\bin -Dfile.encoding=UTF-8 -classpath D:\download\tool\jdk\jdk8_64\install\jre\lib\charsets.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\deploy.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\access-bridge-64.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\cldrdata.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\dnsns.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\jaccess.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\jfxrt.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\localedata.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\nashorn.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunec.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunjce_provider.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunmscapi.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\sunpkcs11.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\ext\zipfs.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\javaws.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jce.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jfr.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jfxswt.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\jsse.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\management-agent.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\plugin.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\resources.jar;D:\download\tool\jdk\jdk8_64\install\jre\lib\rt.jar;D:\project_idea\spring\target\classes;D:\download\tool\versionControl\maven\localRepository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-beans\5.0.0.RELEASE\spring-beans-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-context\5.0.0.RELEASE\spring-context-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-aop\5.0.0.RELEASE\spring-aop-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-core\5.0.0.RELEASE\spring-core-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-jcl\5.0.0.RELEASE\spring-jcl-5.0.0.RELEASE.jar;D:\download\tool\versionControl\maven\localRepository\org\springframework\spring-expression\5.0.0.RELEASE\spring-expression-5.0.0.RELEASE.jar;D:\download\tool\ide\idea\2016\ideaIU-2016\install\lib\idea_rt.jar com.intellij.rt.execution.application.AppMain com.ruge.test.test
十一月 01, 2017 9:30:56 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5387f9e0: startup date [Wed Nov 01 21:30:56 CST 2017]; root of context hierarchy
十一月 01, 2017 9:30:57 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
hello:刘德华

Process finished with exit code 0

spring 5.0 从入门到放弃 01_第1张图片

你可能感兴趣的:(spring)