title: Spring boot WAR in tomcat - externalize the application.properties
body: <p>I have a Spring boot app that is packaged as a WAR and deployed into tomcat.
  It is deployed this way because of some legacy issues.</p>
  
  <p>I am having issues externalizing the application.properties<br>
  DevOps team require the file to be under /app/shared/conf/<br>
  I found many questions about this topic but none of the solutions seems to work...<br>
  This is what I tried so far:  </p>
  
  <p>added to tomcat's Context.xml:</p>
  
  <pre><code>&lt;Parameter name="spring.config.location" value="/app/shared/conf/application.properties" /&gt;
  </code></pre>
  
  <p>added to startup.sh:</p>
  
  <pre><code>export spring_config_location=/app/shared/conf/
  </code></pre>
  
  <p>added to startup.sh:</p>
  
  <pre><code>export SPRING_CONFIG_LOCATION=/app/shared/conf/application.properties
  </code></pre>
  
  <p>added to startup.sh , and setting this on SecurityConfig extends WebSecurityConfigurerAdapter</p>
  
  <pre><code>CLASSPATH=/app/shared/conf/
  @PropertySource("classpath:application.properties")
  </code></pre>
  
  <p>Added to application main class:</p>
  
  <pre><code> System.setProperty("spring.config.location", "/app/shared/conf/application.properties");
  </code></pre>
  
  <p>Added to SecurityConfig extends WebSecurityConfigurerAdapter</p>
  
  <pre><code>@PropertySource("file:/app/shared/conf/application.properties")
  </code></pre>
  
  <p>This is the error I keep getting:</p>
  
  <pre><code> .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::             (v2.2.0.M1)
  
  11-Jun-2019 02:54:22.034 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
   org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/prntPrtl]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
      at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)
      at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThrexeroxoolExecutor.runWorker(ThrexeroxoolExecutor.java:1142)
      at java.util.concurrent.ThrexeroxoolExecutor$Worker.run(ThrexeroxoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xerox.printHub.app.PrinterPortal]; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
      at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
      at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
      at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:785)
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:407)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
      at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
      at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
      at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
      at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 10 more
  Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
      at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159)
      at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:99)
      at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:73)
      at org.springframework.core.io.support.PropertiesLoaderUtils.loxeroxroperties(PropertiesLoaderUtils.java:59)
      at org.springframework.core.io.support.ResourcePropertySource.&lt;init&gt;(ResourcePropertySource.java:67)
      at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37)
      at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:452)
      at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:271)
      at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:191)
      at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:295)
      at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
      ... 26 more
  </code></pre>