在 Web 应用程序中运行时动态加载 Spring 上下文
我正在将使用 Spring Framework 的标准 Java 应用程序转换为 Web 应用程序。此应用程序根据运行时参数加载新的 Spring Context,这是使用 ClassPathXmlApplicationContext/FileSystemXmlApplicationContext 完成的。
所以我的问题是如何在 Web 应用程序中执行相同的操作,因为我已经配置了 web.xml 并添加了 Spring 侦听器,如下所示:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
另一个问题,我的部署环境位于 Tomcat 5.5 上,在该环境中我无法看到任何日志记录spring 上下文加载就知道出了什么问题。
I'm converting a standard Java Application that uses Spring Framework into a Web App. This application loads new Spring Context based on run-time parameters, that was done using ClassPathXmlApplicationContext/FileSystemXmlApplicationContext
.
So my question is how to do the same in a Web Application given that I already configured my web.xml and added Spring Listeners as below:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Another Problem, my deployment environment is on Tomcat 5.5 where I'm not able to see any logging during spring context loading to know what's wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确实打算在启动网络应用时加载可配置的上下文,则可以使用上下文名称的属性占位符来配置 web.xml。
If you actually mean to load a configurable context on start up of your weblication you could configure your web.xml with a property placeholder for the context name.
要打开日志记录,您可能需要在 log4j.properties 文件中进行设置,如下所示:
log4j.logger.org.springframework=DEBUG
您还必须确保您正在登录到控制台而不是其他流。如果是的话,日志消息应该出现在 catalina.out 中
To turn on logging you may need to set it in your log4j.properties file, like so:
log4j.logger.org.springframework=DEBUG
You also have to ensure that you are logging to the CONSOLE and not some other stream. If you are then log messages should appear in catalina.out