title: Why can't my web application application context load my jar properties file?
body: <p>Here is my setup / context.  I have a JAR project that is using spring-boot 1.1.4 which uses Java configuration to load a properties file:</p>
  
  <pre><code>@Configuration
  @ComponentScan
  @EnableAutoConfiguration
  @PropertySource(name="appProps", value="classpath*:application-${spring.profiles.active}.properties")
  public class DataJpaApplication {
  
  
  @Autowired Environment env;
  
  
  @Bean
  //note, this PSPSHC is ours derived from the Spring one with specialized code.
  public static org.springframework.context.support.PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
      PropertySourcesPlaceHolderConfigurer encryptionPropertySourcesPlaceHolderConfigurer = new PropertySourcesPlaceHolderConfigurer();
      encryptionPropertySourcesPlaceHolderConfigurer
              .setIgnoreUnresolvablePlaceholders(true);
      return encryptionPropertySourcesPlaceHolderConfigurer;
  }
  }
  </code></pre>
  
  <p>This jar works fine with unit tests standalone.   I then try to incorporate it into a web app (spring mvc web app not using spring-boot) making it a maven dependency and adding it to the context like this:</p>
  
  <pre><code>&lt;beans:bean id="jpaConfigBean"
      class="com.somepackage.DataJpaApplication" /&gt;
  </code></pre>
  
  <p>I have a web app unit test that attempt to load the web app's application context and that works fine (including loading the context and property file from the jar).  However, when I deploy this web app to a container (tcServer), it fails with the following:</p>
  
  <pre><code>Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/application-local.properties]
  </code></pre>
  
  <p><strong>edit</strong></p>
  
  <p>A clarification about the error above.  The web app is loading its context and importing the jar file's context.  It is this jar project that is loading the application-local.properties via @PropertySource.  So, could this be around parent/child context interactions?</p>
  
  <p>NOTE: No where does the code prepend a slash.</p>
  
  <p>Here is how I am bootstrapping the spring config in the web app:</p>
  
  <pre><code>&lt;servlet&gt;
  &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
  &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
  &lt;init-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;classpath*:**/servlet-context.xml&lt;/param-value&gt;
  &lt;/init-param&gt;
  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  </code></pre>
  
  <p>I have checked the following types of things:</p>
  
  <ol>
  <li>Confirmed the maven generated manifest has a classpath entry for the jar file in the war file.</li>
  <li>Changing the web.xml to use /WEB-INF/servlet-context.xml (standard path) instead</li>
  <li>Deploy this web app in JBoss instead of tc</li>
  <li>move the application-*.property file to another folder and refer to that folder</li>
  <li>copy the *.property file to the web app project</li>
  <li>confirmed the WTP deployment assembly in fact references maven</li>
  <li>opened up the generated war file and confirmed the jar file has the file in the expected location.</li>
  </ol>
  
  <p>and several other things with no success.</p>
  
  <p>I don't see the issue.  Please help figure out where the bug/misconfiguration is.   Also, let me know if there is further configuration or files you need to see to help debug this issue.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Scott</p>
  
  <p><strong><em>edit</em></strong></p>
  
  <p>complete web.xml </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
  
    &lt;context-param&gt;
        &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;log4j.xml&lt;/param-value&gt;
     &lt;/context-param&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
   &lt;!-- commented out for debugging...trying to reduce the complexity to get to root cause
   &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          classpath*:**/*Context.xml,     
          classpath*:**/*-context.xml
       &lt;/param-value&gt;
    &lt;/context-param&gt; --&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;classpath*:**/servlet-context.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter&gt;
      &lt;filter-name&gt;springOpenEntityManagerInViewFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
     &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
     &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
   &lt;filter-mapping&gt;
      &lt;filter-name&gt;springOpenEntityManagerInViewFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  &lt;listener&gt;
    &lt;listener-class&gt;
      org.springframework.security.web.session.HttpSessionEventPublisher
    &lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;error-page&gt;
      &lt;error-code&gt;404&lt;/error-code&gt;
      &lt;location&gt;/WEB-INF/views/404.jsp&lt;/location&gt;
  &lt;/error-page&gt; 
  &lt;error-page&gt;
      &lt;error-code&gt;500&lt;/error-code&gt;
      &lt;location&gt;/WEB-INF/views/500.jsp&lt;/location&gt;
  &lt;/error-page&gt;
  &lt;error-page&gt;
   &lt;location&gt;/WEB-INF/views/500.jsp&lt;/location&gt;
  &lt;/error-page&gt;  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>complete (obfuscated) servlet-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:cache="http://www.springframework.org/schema/cache" xmlns:task="http://www.springframework.org/schema/task"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"&gt;
  
      &lt;beans:bean id="jpaConfigBean"
          class="com.somepackage.DataJpaApplication" /&gt;
  
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
          infrastructure --&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.somepackage.*" /&gt;
  
      &lt;!-- Needed for transaction methods in controllers --&gt;
      &lt;tx:annotation-driven /&gt;
  
      &lt;beans:bean id="ehCacheManager"
          class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
          p:shared="true" /&gt;
  
      &lt;beans:bean id="cacheManager"
          class="org.springframework.cache.ehcache.EhCacheCacheManager"
          p:cacheManager-ref="ehCacheManager" /&gt;
  
      &lt;cache:annotation-driven cache-manager="cacheManager" /&gt;
  
      &lt;task:scheduled-tasks&gt;
          &lt;task:scheduled ref="runScheduler" method="run" cron="0 0 3 * * *" /&gt;
          &lt;task:scheduled ref="runScheduler" method="run"
              initial-delay="0" fixed-rate="#{ T(java.lang.Long).MAX_VALUE }" /&gt;
      &lt;/task:scheduled-tasks&gt;
  
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;annotation-driven conversion-service="conversionService" /&gt;
  
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
          in the /WEB-INF/views directory --&gt;
      &lt;beans:bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="validator"
          class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /&gt;
  
      &lt;beans:bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /&gt;
  
      &lt;beans:bean id="contentNegotiationManager"
          class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"&gt;
          &lt;beans:property name="favorPathExtension" value="true" /&gt;
          &lt;beans:property name="favorParameter" value="false" /&gt;
          &lt;beans:property name="ignoreAcceptHeader" value="false" /&gt;
          &lt;beans:property name="mediaTypes"&gt;
              &lt;beans:value&gt;
                  html=text/html
                  json=application/json
                  xml=application/xml
              &lt;/beans:value&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Not sure there is anything relevant in these files besides what I highlighted above, but added per request and for clarity.</p>