Getting Spring Application Context
来源:互联网 发布:江苏卫视网络电视直播 编辑:程序博客网 时间:2024/04/29 16:15
Is there a way to statically/globally request a copy of the ApplicationContext
in a Spring application?
Assuming the main class starts up and initializes the application context, does it need to pass that down through the call stack to any classes that need it, or is there a way for a class to ask for the previously created context? (Which I assume has to be a singleton?)
If the object that needs access to the container is a bean in the container, just implement the BeanFactoryAware
or ApplicationContextAware
interfaces.
If an object outside the container needs access to the container, I’ve used a standard GoF singleton pattern for the spring container. That way, you only have one singleton in your application, the rest are all singleton beans in the container.
You can implement ApplicationContextAware
or just use @Autowired
:
public class SpringBean { @Autowired private ApplicationContext appContext;}
SpringBean
will have ApplicationContext
injected, within which this bean is instantiated. For example if you have web application with a pretty standard contexts hierarchy:
main application context <- (child) MVC context
and SpringBean
is declared within main context, it will have main context injected; otherwise, if it’s declared within MVC context, it will have MVC context injected.
- Getting Spring Application Context
- Getting Spring Application context from a non bean object
- Spring Application Context
- Spring Service Application Context
- Spring的servlet context和application context
- Spring in Action 3 - application context
- Spring application-context.xml 的 xmlns配置
- JUnit custom runner with Spring application context
- application context
- 【Spring学习笔记】Spring中Application Context和Servlet Context的区别
- Spring的春天,直接召唤系--Singleton的Application Context
- spring:<context:property-placeholder location="classpath:application.properties" />
- spring:<context:property-placeholder location="classpath:application.properties" />
- How to get spring application context object reference?
- spring:<context:property-placeholder location="classpath:application.properties" />
- Activity context And Application context
- Application Context 和 Activity Context
- Singleton的Application Context
- OSI七层模型详解
- cpan安装模块
- 将assets文件夹中的文件复制到sd卡中
- 一篇搞定iOS 9适配--系列教程
- Linux用到的指令<小记>
- Getting Spring Application Context
- Linux命令英文全称
- Android studio把一段代码快速提取,放在自己定义方法里面的快捷键
- 操作系统的CPU监控,基于Unix/linux系统
- 字符串函数
- something about consistency form my perspective
- 修改注册表对付病毒、木马、后门及黑客程序
- 大众点评网2016校招试题选录
- 【转】Unity中HideInInspector和SerializeField一起使用