Spring 4 + Hibernate 4的web程序中 获取Spring Context

来源:互联网 发布:java中问号是什么意思 编辑:程序博客网 时间:2024/06/15 19:13

理想情况下,所有的Bean都应该是由Spring注入的。


当然也会碰到一些特殊情况下,需要在DAO,Service中需要获取Spring Context 以便于获取context中已经声明的对象。


Spring 4 (以前版本未知哈~) 中的 org.springframework.web.context.ContextLoader有个public static方法getCurrentWebApplicationContext(),通过此方法可以获取当前Spring由web.xml注入的一系列配置。

0 0