码迷,mamicode.com
首页 > 其他好文 > 详细

源码注释性容器的创建及初始化

时间:2015-04-02 01:05:29      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); 
MyService myService = ctx.getBean(MyService.class);  // by type... myService.doStuff();

动态注册:

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); 
ctx.register(AppConfig.class, OtherConfig.class);
ctx.register(AdditionalConfig.class); ctx.refresh(); MyService myService = ctx.getBean(MyService.class); myService.doStuff(); }

 主动扫描package:

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.scan("com.acme");
    ctx.refresh();
    MyService myService = ctx.getBean(MyService.class);
}

 

源码注释性容器的创建及初始化

标签:

原文地址:http://www.cnblogs.com/feika/p/4385690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!