當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring --getBean用法
生活随笔
收集整理的這篇文章主要介紹了
Spring --getBean用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.在初始化時保存ApplicationContext對象
2.通過Spring提供的utils類獲取ApplicationContext對象
3.繼承自抽象類ApplicationObjectSupport
4.繼承自抽象類WebApplicationObjectSupport
5.實現接口ApplicationContextAware
6.通過Spring提供的ContextLoader
?
來說一下實現接口的方法:
@Component public class example implements ApplicationContextAware {private static ApplicationContext context;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {context = applicationContext;}example(){}public static TypeHandler createHandler(Type type) throws Exception{if(type==null){throw new Exception("handler type is null");}return (TypeHandler) context.getBean(type.getShortName()+"Handler");}}實現接口之后,getBrean時要實現類型轉換
總結
以上是生活随笔為你收集整理的Spring --getBean用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode--1371. 每个元音
- 下一篇: Servlet API