首页 > 代码库 > web.xml <context-param>只能放一对<param-name>和<param-value>

web.xml <context-param>只能放一对<param-name>和<param-value>

在tomcat里配置多个实例时,不能使用默认的webAppRootKey,需要明确在web.xml里配置webAppRootKey值,否则在启动时会报错,报错如下示

严重: Exception sending context initialized event to listener instance of class ch.qos.logback.ext.spring.web.LogbackConfigListener
java.lang.IllegalStateException: Web app root system property already set to different value: ‘webapp.root‘ = [C:\apache-tomcat-8.0.32\webapps\weblearn\] instead of [C:\apache-tomcat-8.0.32\webapps\weblearn3\] - Choose unique values for the ‘webAppRootKey‘ context-param in your web.xml files!
	at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:162)
	at ch.qos.logback.ext.spring.web.WebLogbackConfigurer.initLogging(Unknown Source)
	at ch.qos.logback.ext.spring.web.LogbackConfigListener.contextInitialized(Unknown Source)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:585)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1794)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

所以在web.xml里配置了webAppRootKey,因为之前配置了logback的配置,于是将webAppRootKey的配置与logback的配置放在一起,如下示.

	<context-param>
		<param-name>logbackConfigLocation</param-name>
		<param-value>/WEB-INF/config/logback3.xml</param-value>
		<param-name>webAppRootKey</param-name>
		<param-value>weblearn3.root</param-value>
	</context-param>

重启服务器后发现没有上面的报错了,但是服务器日志却不生成到文件里了,于是判断context-param只能放一对param-name和param-value,最后修改如下

	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>weblearn3.root</param-value>
	</context-param>
	<context-param>
		<param-name>logbackConfigLocation</param-name>
		<param-value>/WEB-INF/config/logback3.xml</param-value>
	</context-param>

问题解决

本文出自 “梦里不知身是客” 博客,转载请与作者联系!

web.xml <context-param>只能放一对<param-name>和<param-value>