title: MockMvc and Spring Security - Null FilterChainProxy
body: <p>I need to test my REST Controllers which they are secured using Spring Security. I'm using MockMvc as spring security reference suggests here</p>
  
  <blockquote>
    <p><a href="http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#test-mockmvc" rel="noreferrer">http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#test-mockmvc</a></p>
  </blockquote>
  
  <p>Test:</p>
  
  <pre><code>@ContextConfiguration(locations = "classpath:applicationContext.xml")
  @RunWith(SpringJUnit4ClassRunner.class)
  @WebAppConfiguration
  public class LikesTest {
  
      protected MockMvc mockMvc;
  
      @Autowired
      private WebApplicationContext context;
  
      @Before
      public void setup() {
          mockMvc = MockMvcBuilders
                  .webAppContextSetup(context)
                  //.standaloneSetup(new MessageController())
                  .apply(SecurityMockMvcConfigurers.springSecurity())
                  .build();
      }
  
      @Test
      @WithMockUser("user")
      public void testAddLike() throws Exception {
          mockMvc.perform(get("/like?msgId=4&amp;like=false"));
      }
  }
  </code></pre>
  
  <p>When i'm running the JUnit test, i'm getting this failure trace</p>
  
  <blockquote>
    <p>java.lang.NullPointerException    at
    org.springframework.security.web.FilterChainProxy.getFilters(FilterChainProxy.java:223)</p>
  </blockquote>
  
  <p>Also if remove the bean inside applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy"/&gt;
  </code></pre>
  
  <p>Then i'm getting this failure trace:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: springSecurityFilterChain cannot be
    null. Ensure a Bean with the name springSecurityFilterChain
    implementing Filter is present or inject the Filter to be used.   at
    org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurer.beforeMockMvcCreated(SecurityMockMvcConfigurer.java:62)</p>
  </blockquote>
  
  <p>I have no idea why the FilterChainProxy is null. Inside my Web.xml i have declare the DelegatingFilterProxy with filter-name springSecurityFilterChain and my application works fine. Please help me! Thanks</p>