外部setenv.bat在启动tomcat的时候,已传入变量。 但是 程序,好像没有收到。 扔出异常了。 高手

J2EE 码拜 5年前 (2016-09-15) 992次浏览
外部setenv.bat在启动tomcat的时候,已传入变量。 但是 程序,好像没有收到。 扔出异常了。 高手给分析一下!
菜鸟,先谢过大虾!
@REM ***************************************************************************
@REM
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_CONF=”%CATALINA_HOME%/qcadoo””
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_RESTART_CMD=”%CATALINA_HOME%/bin/restart.bat””
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_PLUGINS_PATH=”%CATALINA_HOME%/webapps/ROOT/WEB-INF/lib””
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_PLUGINS_TMP_PATH=”%CATALINA_HOME%/webapps/ROOT/tmp””
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_WEBAPP_PATH=”%CATALINA_HOME%/webapps/ROOT””
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_LOG=”%CATALINA_HOME%/logs””
set “JAVA_OPTS=%JAVA_OPTS% -Dspring.profiles.default=standalone”
set “JAVA_OPTS=%JAVA_OPTS% -javaagent:%CATALINA_HOME%/lib/aspectjweaver-1.8.2.jar”
set “JAVA_OPTS=%JAVA_OPTS% -XX:MaxMetaspaceSize=256m”
set “CATALINA_OPTS=%CATALINA_OPTS% -server -Djava.awt.headless=true”

root-context.xml里的配置如下:
<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:util=”http://www.springframework.org/schema/util”
xmlns:context=”http://www.springframework.org/schema/context”
xmlns:task=”http://www.springframework.org/schema/task”
xsi:schemaLocation=”
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd”>
<context:property-placeholder
location=”
            file:${QCADOO_CONF}/app.properties,
file:${QCADOO_CONF}/connectors.properties,
file:${QCADOO_CONF}/db.properties,
file:${QCADOO_CONF}/mail.properties,
file:${QCADOO_CONF}/mailing.properties,
file:${QCADOO_CONF}/report.properties”

ignore-resource-not-found=”true”
ignore-unresolvable=”true”
properties-ref=”defaultConfiguration”/>
<util:properties id=”defaultConfiguration”>
<prop key=”samplesDatasetLocale”>default</prop>
<prop key=”showContextualHelpPaths”>false</prop>
</util:properties>
<bean id=”log4jConfigurer” class=”org.springframework.beans.factory.config.MethodInvokingFactoryBean”>
<property name=”targetClass”>
<value>org.springframework.util.Log4jConfigurer</value>
</property>
<property name=”targetMethod”>
<value>initLogging</value>
</property>
<property name=”arguments”>
<list>
                <value>file:${QCADOO_CONF}/log4j.xml</value>
</list>
</property>
</bean>
<bean id=”logdiggerFilter” class=”com.logdigger.connector.servlet.LogDiggerConnectorFilter”>
<property name=”config” value=”${logdigger}”/>
</bean>
<task:annotation-driven executor=”wrappedExecutor”/>
<bean id=”wrappedExecutor” class=”com.qcadoo.commons.tasks.DefaultAsyncTaskExecutorWrapper”>
<constructor-arg ref=”executor”/>
</bean>
<task:executor id=”executor” rejection-policy=”CALLER_RUNS”/>
</beans>

八月 31, 2016 1:20:01 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name “log4jConfigurer” defined in ServletContext resource [/WEB-INF/root-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder “QCADOO_CONF” in string value “file:${QCADOO_CONF}/log4j.xml”    //报错
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder “QCADOO_CONF” in string value “file:${QCADOO_CONF}/log4j.xml” //报错
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:173)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.util.SystemPropertyUtils.resolvePlaceholders(SystemPropertyUtils.java:80)
at org.springframework.util.SystemPropertyUtils.resolvePlaceholders(SystemPropertyUtils.java:63)
at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
at org.springframework.beans.factory.config.MethodInvokingFactoryBean.doInvoke(MethodInvokingFactoryBean.java:162)
at org.springframework.beans.factory.config.MethodInvokingFactoryBean.afterPropertiesSet(MethodInvokingFactoryBean.java:152)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)
… 36 more
解决方案

20

你指定的
set “JAVA_OPTS=%JAVA_OPTS% -DQCADOO_RESTART_CMD=”%CATALINA_HOME%/bin/restart.bat””
设置的是JVM 参数。
为什么root-context.xml会取到这个变量值

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明外部setenv.bat在启动tomcat的时候,已传入变量。 但是 程序,好像没有收到。 扔出异常了。 高手
喜欢 (0)
[1034331897@qq.com]
分享 (0)