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.

Spring JIRA | Rémi Doolaeghe | 12 months ago
  1. 0

    I try to write a unit test for a controller in Spring MVC, involving Spring Security. For isolation purpose, I need to mock the service present in a Rest controller. To do this, I use this piece of code: {code:java} @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = EasyCook.class) @WebIntegrationTest public class RecipesControllerCan { @Mock private RecipesService recipesService; @InjectMocks private RecipesController controller; @Autowired private WebApplicationContext wac; @Before public void startMocks(){ controller = wac.getBean(RecipesController.class); MockMvc mockMvc = MockMvcBuilders .standaloneSetup(controller) .alwaysDo(print()) .apply(SecurityMockMvcConfigurers.springSecurity()) .build(); MockitoAnnotations.initMocks(this); } @Test public void testMe(){ } } {code} This leads to this result: 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) at org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:133) at fr.easycompany.easycook.springboot.controllers.RecipesControllerCan.startMocks(RecipesControllerCan.java:51) For more details, I joined the project simplified as much as possible to reproduce the issue.

    Spring JIRA | 12 months ago | Rémi Doolaeghe
    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.
  2. 0

    SEC-3174: Combine Spring Security Test and MockMVC throws IllegalStateException

    GitHub | 12 months ago | spring-issuemaster
    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.
  3. 0

    I try to write a unit test for a controller in Spring MVC, involving Spring Security. For isolation purpose, I need to mock the service present in a Rest controller. To do this, I use this piece of code: {code:java} @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = EasyCook.class) @WebIntegrationTest public class RecipesControllerCan { @Mock private RecipesService recipesService; @InjectMocks private RecipesController controller; @Autowired private WebApplicationContext wac; @Before public void startMocks(){ controller = wac.getBean(RecipesController.class); MockMvc mockMvc = MockMvcBuilders .standaloneSetup(controller) .alwaysDo(print()) .apply(SecurityMockMvcConfigurers.springSecurity()) .build(); MockitoAnnotations.initMocks(this); } @Test public void testMe(){ } } {code} This leads to this result: 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) at org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:133) at fr.easycompany.easycook.springboot.controllers.RecipesControllerCan.startMocks(RecipesControllerCan.java:51) For more details, I joined the project simplified as much as possible to reproduce the issue.

    Spring JIRA | 12 months ago | Rémi Doolaeghe
    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.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    MockMvc and Spring Security - Null FilterChainProxy

    Stack Overflow | 1 year ago | Senpai
    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.
  6. 0

    org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/mmasgis]]

    Stack Overflow | 3 years ago | arpho
    org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/mmasgis]]

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. 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()
    2. org.springframework.security
      SecurityMockMvcConfigurer.beforeMockMvcCreated
      1. org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurer.beforeMockMvcCreated(SecurityMockMvcConfigurer.java:62)
      1 frame
    3. Spring TestContext
      AbstractMockMvcBuilder.build
      1. org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:133)
      1 frame
    4. fr.easycompany.easycook
      RecipesControllerCan.startMocks
      1. fr.easycompany.easycook.springboot.controllers.RecipesControllerCan.startMocks(RecipesControllerCan.java:51)
      1 frame