title: Spring Java configuration with spring-security
body: <p>For some reason (I really cant rembember why :) ) I decided to only use Java for configuration of a Spring application. Also I would try to avoid web.xml</p>
  
  <p>I started with the follinging two java configuration files.
  ApplicationBootstrap.java</p>
  
  <pre><code>public class ApplicationBootstrap implements WebApplicationInitializer {
      //public class Initializer 
      public void onStartup(ServletContext servletContext) throws ServletException {
          AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
          rootContext.register(ApplicationConfig.class);
          rootContext.refresh();
  
      // Manage the lifecycle of the root appcontext
      servletContext.addListener(new ContextLoaderListener(rootContext));
      servletContext.setInitParameter("defaultHtmlEscape", "true");
      servletContext.setInitParameter("spring.profiles.active", "Production");
  
  
       // now the config for the Dispatcher servlet
      AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
          mvcContext.register(ApplicationConfig.class);
          mvcContext.getEnvironment().setActiveProfiles("Production");
          mvcContext.getEnvironment().setDefaultProfiles("Production");
  
      ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/api/*");
  
  
  }
  </code></pre>
  
  <p>and ApplicationConfig.java</p>
  
  <pre><code>@Configuration()
  @Profile({"Production", "ControllerUnitTest"})
  @EnableWebMvc
  @ComponentScan( basePackages = "com.consius.activework.server"  ) 
  @EnableAspectJAutoProxy
  public class ApplicationConfig extends WebMvcConfigurerAdapter {
  
  
  }
  </code></pre>
  
  <p>This worked as espected. No my problem started. My idea was to use spring-security and I looked for a way to configure spring-security using Java. 
  After a while I gave up,, I found no way to configure spring-security using Java.
  I decided to go back to XML for the security configuration.</p>
  
  <p>I created a web.xml containing this:</p>
  
  <pre><code>   &lt;filter&gt;
          &lt;filter-name&gt;filterChainProxy&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;filterChainProxy&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>To the ApplicationConfig.java I added:</p>
  
  <pre><code> @ImportResource( { "classpath:/spring-security.xml" } )
  </code></pre>
  
  <p>And created a new xml file named spring-security.xml</p>
  
  <pre><code>&lt;security:http auto-config='true' create-session="never" realm="Restricted Service" use-expressions="true"&gt;
      &lt;security:intercept-url pattern="/rest/**" access="permitAll()" /&gt;               
  &lt;/security:http&gt;
  </code></pre>
  
  <p>According documentation this is minimal configuration.</p>
  
  <p>Trying to run this gives the following error (and I cant understand why)</p>
  
  <pre><code>SEVERE: Exception starting filter filterChainProxy
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'filterChainProxy' is defined
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:549)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1096)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1121)
      at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326)
      at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:236)
      at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:194)
      at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
  </code></pre>
  
  <p>Can anyone help me?
  I guess I have done something obvious wrong,, but I cant see it.</p>
  
  <p>//lg</p>