title: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined - Java Based Configuration
body: <p>Trying to resolve <code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined</code> in Java based configuration.</p>
  
  <p>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"
           id="WebApp_ID" version="3.0"&gt;
  
      &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&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;contextClass&lt;/param-name&gt;
              &lt;param-value&gt;org.springframework.web.context.support.AnnotationConfigWebApplicationContext&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;com.examples.config.WebAppConfig&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;!-- Spring Security --&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-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;error-page&gt;
          &lt;error-code&gt;404&lt;/error-code&gt;
          &lt;location&gt;/WEB-INF/views/error/404.jsp&lt;/location&gt;
      &lt;/error-page&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The WebAppCinfig java based:</p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  @Import(value = SecurityConfig.class)
  @ComponentScan(basePackages = {"com.examples"})
  @ImportResource({ "classpath:spring-security-config.xml" })
  public class WebAppConfig extends WebMvcConfigurerAdapter {
  
      public WebAppConfig() {
          super();
      }
  
      @Override
      public void addViewControllers(final ViewControllerRegistry registry) {
          super.addViewControllers(registry);
  
          registry.addViewController("/anonymous.html");
  
          registry.addViewController("/login.html");
          registry.addViewController("/homepage.html");
      }
  
      @Bean
      public ViewResolver viewResolver() {
          final InternalResourceViewResolver bean = new InternalResourceViewResolver();
  
          bean.setViewClass(JstlView.class);
          bean.setPrefix("/WEB-INF/views/");
          bean.setSuffix(".jsp");
  
          return bean;
      }
  }
  </code></pre>
  
  <p>The SecurityConfig.java file for the security:</p>
  
  <pre><code>@Configuration
  @ImportResource({ "classpath:spring-security-config.xml" })
  public class SecurityConfig {
  
      public SecurityConfig() {
          super();
      }
  
  }
  </code></pre>
  
  <p>And finally the WebAppConfig.java class:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:beans="http://www.springframework.org/schema/beans"
               xmlns="http://www.springframework.org/schema/security"
               xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security.xsd"&gt;
  
      &lt;http auto-config="true"&gt;
          &lt;intercept-url pattern="/anonymous*" access="isAnonymous()"/&gt;
          &lt;intercept-url pattern="/login*" access="permitAll"/&gt;
          &lt;intercept-url pattern="/**" access="isAuthenticated()"/&gt;
  
          &lt;form-login login-page='/login.html' login-processing-url="/perform_login"
                      default-target-url="/homepage.html" authentication-failure-url="/login.html?error=true"
                      always-use-default-target="true"/&gt;
  
          &lt;logout logout-url="/perform_logout" delete-cookies="JSESSIONID"
                  success-handler-ref="customLogoutSuccessHandler"/&gt;
  
      &lt;/http&gt;
  
      &lt;beans:bean name="customLogoutSuccessHandler"
                  class="com.examples.config.CustomLogoutSuccessHandler"/&gt;
  
      &lt;authentication-manager&gt;
          &lt;authentication-provider&gt;
              &lt;user-service&gt;
                  &lt;user name="user1" password="pass1" authorities="ROLE_USER"/&gt;
                  &lt;user name="user2" password="pass2" authorities="ROLE_USER"/&gt;
              &lt;/user-service&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Now, I am getting <code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined</code> in a Java base Spring Security project I am working on. Things works on Annotation Configuration well and is testable in a great way. For some reason, Spring does is throwing such an error while trying to accomplish Spring Security Form Login example.</p>
  
  <p>Also in the spring-security-config.xml tried changing <code>&lt;http use-expressions="true"&gt;</code> to <code>&lt;http auto-config="true"&gt;</code>but still no luck resolving No Bean Named <code>'springSecurityFilterChain'</code> found exception.</p>
  
  <p>Any help in this matter would be highly appreciated.
  Thanks,</p>