title: Spring Security Web application context doesn't load beans
body: <h1>Problem</h1>
  
  <p>I can't load beans from <code>spring-beans.xml</code> in addition to programmatic configuration. I've created a custom <code>org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter</code> and annotated the class with the following annotations: <code>@Configuration, @ImportResource('classpath*:spring-beans.xml'), @EnableWebSecurity</code>. As you can see in the logs, no beans are loaded. Why? My goal ist o have a semi flexible configuration. I want to configure some parts in code and some parts in the spring-beans.xml file which should be loaded into the application context on startup. For example i want to define a custom AuthentificationProvider and create it with a custom configuration in the spring-beans.xml file. Whats done with the provider should be fixed in code.</p>
  
  <h2>Logs</h2>
  
  <pre><code>[INFO] 2018-10-23 14:48:05,569 TRACE (Default Executor-thread-11) [PathMatchingResourcePatternResolver(findAllClassPathResources:322)] Resolved classpath location [spring-beans.xml] to resources []
  [INFO] 2018-10-23 14:48:05,573 TRACE (Default Executor-thread-11) [XmlBeanDefinitionReader(loadBeanDefinitions:229)] Loaded 0 bean definitions from location pattern [classpath*:spring-beans.xml]
  </code></pre>
  
  <h2>Javacode</h2>
  
  <pre><code>@Configuration
  @ImportResource({"classpath*:spring-beans.xml"})
  @EnableWebSecurity
  public class HSecurityConfig extends WebSecurityConfigurerAdapter {
  
      // configuration creates a servlet filter known as 'springSecurityFilterChain'
  
      @Autowired ApplicationContext applicationContext;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          // configure some http stuff
      }
  
  }
  </code></pre>
  
  <h2>spring-beans.xml</h2>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:security="http://www.springframework.org/schema/security"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security.xsd"&gt;
  
  &lt;security:authentication-manager&gt;
      &lt;security:authentication-provider ref="myProvider"/&gt;
  &lt;/security:authentication-manager&gt;
  
  &lt;bean id="myProvider"
        class="package.providers.MyProvider"&gt;
      &lt;constructor-arg value="arg1" /&gt;
      &lt;constructor-arg value="arg2" /&gt;
  &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <h1>Dependencies</h1>
  
  <pre><code>&lt;dependencyManagement&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-bom&lt;/artifactId&gt;
              &lt;version&gt;5.1.0.RELEASE&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <h1>Update 1</h1>
  
  <h2>Project Structure</h2>
  
  <p>The project is a standard maven folder structure</p>
  
  <pre><code>├── src
  │   ├── main
  │   │   ├── java
  │   │   ├── resources
  │   │   │   ├── META-INF
  │   │   │   └── spring
  │   │   └── webapp
  │   │       └── WEB-INF
  │   └── test
  │       └── java
  </code></pre>
  
  <h2>Editing of Javacode</h2>
  
  <pre><code>@Configuration
  @ImportResource({"classpath*:/resources/spring/spring-beans.xml"})
  @EnableWebSecurity
  public class HSecurityConfig extends WebSecurityConfigurerAdapter {
  
      // configuration creates a servlet filter known as 'springSecurityFilterChain'
  
      @Autowired ApplicationContext applicationContext;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          // configure some http stuff
      }
  
  }
  </code></pre>
  
  <p>After updating the code, the log stays the same saying: '...Loaded 0 beans...'.</p>