spring3 升级4 spring security4.2.x配置

为了体验一下java8,只好把spring3升级到了4,因为Spring3对java8不能完全支持。工程采用了maven,因此简单的更改了pom.xml,这个没什么好解释的了,至于spring.xml,spring-mvc.xml,spring-hibernate.xml等文件,只需要把版本改成4.0即可,不贴源码了,改动最大的是spring-security.xml(网上有多种配置方式),如果像我一样对4不甚理解的同学,可以只配置spring-security.xml即可(毕竟跟以前的配置方式相类似)。


spring-security.xml配置参考:

xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-4.2.xsd">
    <security:http pattern="/extjs/**" security="none"/>
    <security:http pattern="/js/**" security="none"/>
    <security:http pattern="/css/**" security="none"/>
    <security:http pattern="/loginlogout/toLogin" security="none"/>
    pattern="/loginlogout/login" security="none"/>
    

    <security:http auto-config="true" use-expressions="true">
        <security:headers>
            <security:frame-options policy="SAMEORIGIN"/>
        security:headers>
        
        <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>

        <security:csrf disabled="true"/>
        <security:form-login login-page="/loginlogout/toLogin"
                             authentication-failure-url="/loginlogout/logout"
                             default-target-url="/menu/toDemo" username-parameter="name" password-parameter="passwd"/>
        <security:logout
                logout-url="/loginlogout/logout"
                logout-success-url="/loginlogout/logout"
        />
        <security:session-management invalid-session-url="/loginlogout/toLogin"
                                     session-fixation-protection="newSession">
            <security:concurrency-control max-sessions="1" expired-url="/loginlogout/toLogin"/>
        security:session-management>
    security:http>
    
    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider ref="authenticationProvider">
        security:authentication-provider>
    security:authentication-manager>
    id="authenticationProvider"
          class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
        name="hideUserNotFoundExceptions" value="false"/>
        name="userDetailsService" ref="customUserDetailsService"/>
        
        
        name="messageSource" ref="messageSource"/>
        
        
        
        
    
    id="customUserDetailsService" class="com.extjs.service.impl.CustomUserDetailsService"/>
    id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        name="basename" value="classpath:messages_zh_CN"/>
    
    
    id="passwordEncode" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>
    id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">
        name="userPropertyToUse" value="username"/>
    

pom.xml完整配置参考:

xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  com.wdy
  TestMaven
  war
  1.0-SNAPSHOT
  TestMaven Maven Webapp
  http://maven.apache.org
  
    UTF-8
    1.8
    1.8
  
  
    
    
      com.oracle
      ojdbc8
      12.1.0.2.0
    
    
    
      log4j
      log4j
      1.2.17
    
    
    
      javax.servlet
      javax.servlet-api
      3.1-b09
      provided
    
    
    
      mysql
      mysql-connector-java
      5.1.24
    
    
    
      com.mchange
      c3p0
      0.9.5-pre2
    
    
    
      junit
      junit
      4.11
      test
    
    
    
      com.alibaba
      fastjson
      1.2.32
    
    
      org.json
      json
      20170516
    

    
    
    
    
      org.springframework
      spring-core
      4.3.9.RELEASE
    
    
      org.springframework
      spring-context
      4.3.9.RELEASE
    
    
      org.springframework
      spring-jdbc
      4.3.9.RELEASE
    
    
      org.springframework
      spring-beans
      4.3.9.RELEASE
    
    
      org.springframework
      spring-web
      4.3.9.RELEASE
    

    
      org.springframework
      spring-webmvc
      4.3.9.RELEASE
    


    
      org.springframework
      spring-expression
      4.3.9.RELEASE
    
    
      org.springframework
      spring-orm
      4.3.9.RELEASE
    
    
    
      org.aspectj
      aspectjweaver
      1.8.10
    
    
    
      org.hibernate
      hibernate-core
      4.2.0.Final
    

    
    
      org.springframework.security
      spring-security-core
      4.2.3.RELEASE
    
    
      org.springframework.security
      spring-security-web
      4.2.3.RELEASE
    

    
      org.springframework.security
      spring-security-config
      4.2.3.RELEASE
    
    
      org.springframework.security
      spring-security-taglibs
      4.2.3.RELEASE
    

    
    
      jstl
      jstl
      1.2
    
    
    
      org.codehaus.jackson
      jackson-core-asl
      1.9.13
    
    
      org.codehaus.jackson
      jackson-mapper-asl
      1.9.13
    
    
      com.fasterxml.jackson.core
      jackson-databind
      2.8.8.1
    
    
    
      org.apache.commons
      commons-lang3
      3.5
    
    
      commons-io
      commons-io
      2.5
    
    
      commons-fileupload
      commons-fileupload
      1.3.2
    
    
    
      org.apache.poi
      poi
      3.16
    
    
      org.apache.poi
      poi-excelant
      3.16
    
    
      org.apache.poi
      poi-ooxml
      3.16
    
    
      org.apache.poi
      poi-ooxml-schemas
      3.16
    
    
      org.apache.poi
      poi-scratchpad
      3.16
    
    
    
      org.freehep
      freehep-graphicsio
      2.4
    
    
      org.freehep
      freehep-graphicsio-emf
      2.4
    
    
      org.freehep
      freehep-util
      2.1.1
    
    
      org.freehep
      freehep-io
      2.2.2
    

  
  
    TestMaven
  


你可能感兴趣的:(spring3 升级4 spring security4.2.x配置)