1

I already have a XML based Spring application. I have been asked to integrate Spring Security into it. I want to use Java based config. I have already initialized it as per the instructions here: Java Config but how and where do I load the SecurityConfig class.

My web.xml is:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/site.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

My SecurityWebApplicationInitializer is:

public class SecurityWebApplicationInitializer extends
AbstractSecurityWebApplicationInitializer {

}

My SecurityConfig is:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll();
    }
}

1 Answer 1

3

You need to add @Configuration annotation to SecurityConfig.

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

}

Add component scan tag in your spring configuration XML file:

<context:component-scan base-package="<yourPackageName>" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.