title: Spring MVC : How to load @PropertySource from WEB-INF
body: <p>I use Spring MVC with java config.</p>
  
  <p>And I have two context configuration classes: <code>RootContext</code> and <code>ServletContext</code>.</p>
  
  <p>RootContext class is loaded via <code>&lt;context-param&gt;</code> in web.xml</p>
  
  <p>Here is the code of RootContext:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @Import(DaoConfig.class)
  @PropertySource("/WEB-INF/config/application.properties")
  public class RootContext {
  
      @Autowired
      private Environment env;
  
      @Bean(destroyMethod = "close")
      public DataSource dataSource() {
          BasicDataSource dataSource = new BasicDataSource();
          dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
          dataSource.setUrl(env.getProperty("jdbc.url"));
          dataSource.setUsername(env.getProperty("jdbc.username"));
          dataSource.setPassword(env.getProperty("jdbc.password"));
          return dataSource;
      }
  
      @Bean
      public PlatformTransactionManager transactionManager() {
          return new DataSourceTransactionManager(dataSource());
      }
  }
  </code></pre>
  
  <p>If I run the application, I got this error:</p>
  
  <pre><code>java.io.FileNotFoundException: class path resource [WEB-INF/config/application.properties] cannot be opened because it does not exist
  </code></pre>
  
  <p>Everything works fine if I move <code>application.properties</code> file to classpath. But I want it to be in /WEB-INF/config directory.</p>
  
  <p>Any suggestion how to solve this error?</p>
  
  <p>Should I put <code>@PropertySource("/WEB-INF/config/application.properties")</code> line to ServletContext instead of RootContext??</p>
  
  <p>Thank you.</p>