Spring获取ApplicationContext对象工具类的实现方法

栏目: 编程语言 · ASP.NET · 发布时间: 7年前

内容简介:这篇文章主要介绍了 Spring获取ApplicationContext对象工具类的实现方法的相关资料,希望通过本文能帮助到大家,让大家实现这样的功能,需要的朋友可以参考下

 Spring获取ApplicationContext对象 工具 类的实现方法

(1)实现的工具类:

package com.util; 
 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
 
final public class ApplicationContextUtil { 
 
  private static ApplicationContext ac=null; 
   
  private ApplicationContextUtil(){ 
     
  } 
   
  static{ 
    ac=new ClassPathXmlApplicationContext("applicationContext.xml"); 
  } 
   
  public static ApplicationContext getApplicationContext(){ 
    //获得返回的容器对象 
    return ac; 
  } 
   
} 

(2)使用方法:

public static void getByUtil(){ 
    ApplicationContextUtil.getApplicationContext().getBean("userService"); 
  }  

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

程序员的思维修炼

程序员的思维修炼

Andy Hunt / 崔康 / 人民邮电出版社 / 2010-12-10 / 39.00元

本书解释了为什么软件开发是一种精神活动,思考如何解决问题,并就开发人员如何能更好地开发软件进行了评论。书中不仅给出了一些理论上的答案,同时提供了大量实践技术和窍门。 本书供各层次软件开发人员阅读。一起来看看 《程序员的思维修炼》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具