Senpai Senpai - 4 months ago 136
Java Question

MockMvc and Spring Security - Null FilterChainProxy

I need to test my REST Controllers which they are secured using Spring Security. I'm using MockMvc as spring security reference suggests here


@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class LikesTest {

protected MockMvc mockMvc;

private WebApplicationContext context;

public void setup() {
mockMvc = MockMvcBuilders
//.standaloneSetup(new MessageController())

public void testAddLike() throws Exception {

When i'm running the JUnit test, i'm getting this failure trace

java.lang.NullPointerException at

Also if remove the bean inside applicationContext.xml:

<bean id="springSecurityFilterChain" class=""/>

Then i'm getting this failure trace:

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

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


I've managed to get it working. Just make sure you have the correct Context Configurations. Also you don't need to declare a FilterChainProxy bean. Thanks