spring 容器的简述 | 您所在的位置:网站首页 › 简述spring容器的启动过程 › spring 容器的简述 |
spring容器的简单测试 在maven中引入spring-context(常用的容器管理spring-context集成了许多jar包) 写一个testservice @Service public class TestService{ public void sayHello(String word){ return "hello "+word; } } 写一个配置类,相当于xml配置文件 @Configuration @ComponentScan("xx.xx.xx") public class JavaConfig(){ } 写一个启动类 public class Main(){ 根据配置类获取容器 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JavaConfig.class);//引入配置类 TestService testService = context.getBean(TestService .class);//根据指定类获取bean System.out.println(testService.sayHello("world"));}
是不是非常简单非常干净的一个小程序!
|
CopyRight 2018-2019 实验室设备网 版权所有 |