Sangam Jung Gauli
Sangam Jung Gauli

Reputation: 143

Integrate XML based spring mvc with java config based spring security

I've already done a simple project on spring mvc framework with XML config file. Now I want to add spring security with java config file in that project. Is it possible to integrate. I've almost spend a whole day searching it on google. I've already read documentation but I didn't get any clue. Can anyone provide me good reference for it? Thanks in advance

Upvotes: 0

Views: 53

Answers (1)

M. Deinum
M. Deinum

Reputation: 125252

You have 2 options depending on which is leading, the XML or Java version. Both of them are quite well documented in the Spring Reference Guide.

When using XML you can simply add the @Configuration annotated class as a bean to the XML configuration like any other bean.

<bean class="your.configuration.class.Here" />

You have to have <context:annoation-config /> to have the @Configuration class processed.

However if you already have <context:component-scan /> and the package(s) you are scanning already includes the package that contains the @Configuration class you don't need to do anything as it will be detected like any other @Component.

If you want you have your @Configuration class leading then you can simply import the XML configuration using @ImportResource.

@Configuration
@ImportResource("your-configuration-here.xml")
public class SecurityConfig {}

Either way will work, which depends on which you want to make the leading configuration standard.

Upvotes: 2

Related Questions