【发布时间】:2014-08-17 22:19:57
【问题描述】:
我收到一个错误,我正在部署的应用程序找不到 /WEB-INF/applicationContext.xml。
这是我的 web.xml
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>com.sheidaei.chnlsales.web.util.P13nApplicationContextInitializer</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
这是自定义类:
package com.sheidaei.chnlsales.web.util;
import java.io.IOException;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.support.ResourcePropertySource;
import org.apache.log4j.Logger;
public class P13nApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
protected static Logger LOG = Logger.getLogger(P13nApplicationContextInitializer.class);
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
try {
environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env.properties"));
//environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:root-context.xml"));
environment.getPropertySources().addFirst(new ResourcePropertySource("/WEB-INF/spring/root-context.xml"));
environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:fw-refresh-spring.xml"));
LOG.info("env.properties loaded");
} catch (IOException e) {
// it's ok if the file is not there. we will just log that info.
LOG.info("didn't find env.properties in classpath so not loading it in the AppContextInitialized");
}
}
}
我试图根据这里的讨论创建一个个性化的 ApplicationContextInitializer:How to set active spring 3.1 environment profile via a properites file and not via an env variable or system property 但我没有成功。
在更改为自定义类之前,我的 web.xml 如下所示(并且可以成功部署应用程序)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml,
classpath:fw-refresh-spring.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
-->
【问题讨论】:
-
请发布完整的堆栈跟踪。
标签: java xml spring servlets weblogic