WebApproot在春季 [英] WebApproot in Spring

查看:74
本文介绍了WebApproot在春季的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误消息

[SEVERE:向上下文org.springframework.web.util.Log4jConfigListener的侦听器实例发送上下文初始化事件的异常 java.lang.IllegalStateException:Web应用程序根系统属性已设置为其他值:'webapp.root'= [C:\ Users \ jaanlai \ Documents \ NetBeansProjects \ absSovellus \ build \ web]而非[C:\ Users \ Administrator \ Documents \ NetBeansProjects \ keycard2 \ build \ web]-在web.xml文件中为"webAppRootKey"上下文参数选择唯一的值!

[ SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [C:\Users\jaanlai\Documents\NetBeansProjects\absSovellus\build\web] instead of [C:\Users\Administrator\Documents\NetBeansProjects\keycard2\build\web] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!

这很奇怪,因为我的文件中没有定义任何webAppRootKey.什么事?

It's odd, because I don't have any webAppRootKey defined in my files. What is it?

推荐答案

webAppRootKey是Spring在几个地方使用的上下文参数.在这种情况下,Log4jWebConfigurer正在使用它.它将webapp根作为系统属性公开,可在log4j配置文件中使用,如下所示:

The webAppRootKey is a context parameter that Spring uses in a couple of places. In this case, it's being used by the Log4jWebConfigurer. It exposes the webapp root as a system property that can be used in log4j configuration files, something like this:

log4j.appender.testfile.File=${webapp.root}/WEB-INF/testlog.log 

如果出于某种原因想要找​​到相对于Webapp根目录的日志,则可以使用此选项.

You would use this if you, for some reason, wanted to locate your logs relative to your webapp root.

您遇到的问题是某些容器(尤其是Tomcat)没有维护每个Web应用程序的系统属性映射.当您不指定webAppRootKey时,Spring会将其默认设置为webapp.root.由于您在同一个容器中运行两个应用程序,因此您尝试启动的第二个应用程序会看到webAppRootKey已设置(通过默认值),并引发错误.否则,webAppRootKey的设置将不正确,最终您可能会收到来自另一个Web应用程序中一个Web应用程序的日志.

The problem that you're running into is that some containers (notably Tomcat) don't maintain a per-webapp mapping of system properties. When you don't specify a webAppRootKey, Spring defaults it to webapp.root. Since you're running two apps in the same container, the second app you're trying to start up sees that the webAppRootKey is already set (via the default), and throws an error. Otherwise, the webAppRootKey would be set incorrectly, and you could end up with logs from one webapp in another webapp.

您可以使用web.xml中的上下文参数指定其他webAppRootKey,如下所示:

You can specify a different webAppRootKey using context parameters in your web.xml like so:

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>webapp.root.one</param-value>
</context-param>

还有

log4j.appender.testfile.File=${webapp.root.one}/WEB-INF/testlog.log 

在您的log4j中.这应该解决冲突.

in your log4j. This should take care of the conflict.

这篇关于WebApproot在春季的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆