午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Spring獲取管理對象常用方法詳解

瀏覽:18日期:2023-08-07 08:50:50

網上方法很多種,我說一些J2EE開發中會用到的方法。

第一種:

直接初始化Spring容器,獲得對象

ApplicationContext applicationContext = new ClassPathXmlApplicationContext('applicationContext.xml'); applicationContext.getBean('beanId');

關于配置文件的讀取也有好多種,我用到的是配置文件在SRC下面。

這樣會初始化Spring容器,然后再得到配置的對象。

第二種:

通過環境來獲得

ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext()); ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext()); ac1.getBean('beanId'); ac2.getBean('beanId');

區別是前者會拋異常,而后者沒有時返回NULL

第三種:

實現ApplicationContextAware接口

下面給出實現類,這也是我用的方法

import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; /** * @說明 獲得Spring配置中的某個對象 * @author 崔素強 * @see */ public class SpringFactory implements ApplicationContextAware { private static ApplicationContext context; @SuppressWarnings('static-access') @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.context = applicationContext; } public static Object getObject(String id) { Object object = null; object = context.getBean(id); return object; } }

這是WEB開發中可以用到的集中方法,當然還有其他方法,歡迎大家積極提供!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 玖玖综合网 | 99精品国自产在线 | 日韩中文av | 欧美日韩v | 亚洲美女色 | 国产日日日 | 国产激情毛片 | 国产 欧美 自拍 | av在线影院 | 国产黄色免费 | 黑人巨大精品欧美一区二区 | 在线日韩中文字幕 | 蜜桃成人在线观看 | 色老头一区二区三区在线观看 | 久久网国产 | 一级黄色大片免费观看 | 久久久久久国产精品视频 | 欧美在线视频网 | 国产日韩在线免费观看 | 三级中文字幕 | 国产在线网 | 国产精品久久影院 | 毛片999 | 色综合自拍 | 欧美日韩一区二区不卡 | 偷拍青青草 | 在线观看国产欧美 | 日韩视频中文字幕在线观看 | 中文在线观看免费视频 | 一区二区黄色片 | 久久成人毛片 | 欧美一级特黄视频 | 久久国产精品偷 | 日韩av在线看免费观看 | 婷婷视频网| 亚洲爽爽 | 日本美女黄色一级片 | 婷婷九九| 亚洲精品成人在线 | 亚洲永久精品在线观看 | 欧美片在线观看 |