Spring Security(1) 简单配置

开发环境

  • maven
  • idea
  • jdk 1.8
  • tomcat 8

配置spring mvc + spring security

pom.xml

    
        4.3.8.RELEASE
        4.2.2.RELEASE
    


    
        

        
            org.springframework
            spring-context
            ${spring.version}

        

        
            org.springframework
            spring-webmvc
            ${spring.version}
        

        
        
            org.springframework.security
            spring-security-core
            ${spring-sercurity.version}
        

        
            org.springframework.security
            spring-security-web
            ${spring-sercurity.version}
        

        
            org.springframework.security
            spring-security-config
            ${spring-sercurity.version}
        
    

spring mvc 使用的是4.3.8版本,spring security 使用的是4.2.2版本。

spring-mvc-servlet.xml




    

    
        
            /WEB-INF/pages/
        
        
            .jsp
        
    

spring-security.xml




    
        
    

    
        
            
                
            
        
    

web.xml



    Archetype Created Web Application

    
        org.springframework.web.context.ContextLoaderListener
    

    
        contextConfigLocation
        
            classpath:spring-mvc-servlet.xml,
            classpath:spring-security.xml
        
    

    
    
        spring-mvc
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath*:spring-mvc-servlet.xml
        
        1
    
    
        spring-mvc
        /
    

    
    
        springSecurityFilterChain
        org.springframework.web.filter.DelegatingFilterProxy
    

    
        springSecurityFilterChain
        /*
    

    
        index.jsp
    


测试

spring会拦截所有请求,如果没有登录,则系统会跳转到spring security默认的登录页面。

你可能感兴趣的:(Spring Security(1) 简单配置)