我需要 ApplicationContext.xml
的上下文,我在 web.xml
中将其提供为
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
但是我需要在 Controller
类中对此进行控制。
我尝试了很多东西,包括
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
但这并没有帮助。
最佳答案
最简单的解决方案是使用 getWebApplicationContext()
WebApplicationContextUtils
:
Find the root WebApplicationContext for this web application, which is typically loaded via ContextLoaderListener.
关于java - 如何获取默认的 WebApplicationContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2495741/