源码注释性容器的创建及初始化
生活随笔
收集整理的這篇文章主要介紹了
源码注释性容器的创建及初始化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
MyService myService = ctx.getBean(MyService.class); // by type... myService.doStuff();
ctx.register(AppConfig.class, OtherConfig.class);
ctx.register(AdditionalConfig.class);ctx.refresh();MyService myService = ctx.getBean(MyService.class);myService.doStuff(); }
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); }?
轉載于:https://www.cnblogs.com/feika/p/4385690.html
總結
以上是生活随笔為你收集整理的源码注释性容器的创建及初始化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 构造函数、拷贝构造函数和析构函数的的调用
- 下一篇: [转]java二维码生成与解析代码实现