Referencing Spring Security configuration within Spring 3.1 Java Config

后端 未结 4 679
盖世英雄少女心
盖世英雄少女心 2021-02-04 21:12

I recently switched a majority of my Spring configuration to use the code based config in Spring 3.1. However, now that I\'ve switched, my Spring Security is not working correc

4条回答
  •  生来不讨喜
    2021-02-04 21:27

    For those still looking for a way to use SpringSecurity XML configuration with a Java config web application. I got this working using Spring 3.2.0.RELEASE and SpringSecurity 3.2.0.M1. Here's the important parts of the solution

    WebAppConfig.java

    package com.foo.webapp;
    
    @Configuration
    @ComponentScan(basePackages = { "com.foo" })
    @ImportResource(value = { "/WEB-INF/spring-security.xml" })
    public class WebAppConfig {
        // other beans go here
    }
    

    spring-security.xml
    Note that I had to remove the default xmlns="..." from the definition.

    
    
    
        
            
            
            
        
    
        
            
                
                    
                
            
        
    
    

    web.xml

    
    
    
        
            contextClass
            
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            
        
        
            contextConfigLocation
            com.foo.webapp.WebAppConfig
        
    
        
        
            springSecurityFilterChain
            org.springframework.web.filter.DelegatingFilterProxy
        
        
            springSecurityFilterChain
            /*
        
    
        
            org.springframework.web.context.ContextLoaderListener
        
    
        
            foo
            org.springframework.web.servlet.DispatcherServlet
            1
        
        
            foo
            /
        
    
    

提交回复
热议问题