Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Added Spring Security, now I'm getting "No WebApplicationContext found: no ContextLoaderListener registered?"

I have a Spring web application that is running just fine. I'm using JavaConfig, so there's not a lick of XML in the whole configuration. I'm trying to integrate Spring Security, but when I add a class that extends AbstractSecurityWebApplicationInitializer as directed by this tutorial, I get the following exception:

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:251)
...

Any idea how I can resolve this?

like image 456
simon Avatar asked Dec 06 '25 17:12

simon


1 Answers

You probably need to ensure the security configuration is loaded. If the security configuration is not being loaded by other means, the AbstractSecurityWebApplicationInitializer should pass in the Security configuration to the super class as shown in the guide:

import org.springframework.security.web.context.*;

public class SecurityWebApplicationInitializer
      extends AbstractSecurityWebApplicationInitializer {

    public SecurityWebApplicationInitializer() {
        super(SecurityConfig.class);
    }
}
like image 179
Rob Winch Avatar answered Dec 09 '25 15:12

Rob Winch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!