在 Web 应用程序中运行时动态加载 Spring 上下文

发布于 2024-08-08 06:03:05 字数 475 浏览 11 评论 0原文

我正在将使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆兒滾 2024-08-15 06:03:05

如果您确实打算在启动网络应用时加载可配置的上下文,则可以使用上下文名称的属性占位符来配置 web.xml。

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:${my_context_file}</param-value>
</context-param>

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.

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:${my_context_file}</param-value>
</context-param>
夜访吸血鬼 2024-08-15 06:03:05

要打开日志记录,您可能需要在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文