最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解Spring Security 簡(jiǎn)單配置

 更新時(shí)間:2017年05月25日 15:23:32   作者:憨厚的老菜鳥(niǎo)  
本篇文章主要介紹了詳解Spring Security 簡(jiǎn)單配置,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

開(kāi)發(fā)環(huán)境

  1. maven
  2. idea
  3. jdk 1.8
  4. tomcat 8

配置spring mvc + spring security

pom.xml

 <properties>
  <spring.version>4.3.8.RELEASE</spring.version>
  <spring-sercurity.version>4.2.2.RELEASE</spring-sercurity.version>
 </properties>


 <dependencies>
  <!-- Spring 4 dependencies -->

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>${spring.version}</version>

  </dependency>

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <!-- Spring Security -->
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-core</artifactId>
   <version>${spring-sercurity.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-web</artifactId>
   <version>${spring-sercurity.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-config</artifactId>
   <version>${spring-sercurity.version}</version>
  </dependency>
 </dependencies>

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

spring-mvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-4.0.xsd">

 <context:component-scan base-package="com.controller" />

 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix">
   <value>/WEB-INF/pages/</value>
  </property>
  <property name="suffix">
   <value>.jsp</value>
  </property>
 </bean>
</beans>

spring-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
  xmlns="http://www.springframework.org/schema/security"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security.xsd">

 <http auto-config="true" >
  <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
 </http>

 <authentication-manager>
  <authentication-provider>
   <user-service>
    <user name="admin" password="123456" authorities="ROLE_USER"/>
   </user-service>
  </authentication-provider>
 </authentication-manager>
</beans:beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">
 <display-name>Archetype Created Web Application</display-name>

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

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   classpath:spring-mvc-servlet.xml,
   classpath:spring-security.xml
  </param-value>
 </context-param>

 <!-- spring mvc -->
 <servlet>
  <servlet-name>spring-mvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath*:spring-mvc-servlet.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>spring-mvc</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>

 <!-- spring security -->
 <filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

測(cè)試

spring會(huì)攔截所有請(qǐng)求,如果沒(méi)有登錄,則系統(tǒng)會(huì)跳轉(zhuǎn)到spring security默認(rèn)的登錄頁(yè)面。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JAVA監(jiān)控JMX的使用

    JAVA監(jiān)控JMX的使用

    Java Management Extensions(JMX)提供了一種標(biāo)準(zhǔn)化的方法來(lái)管理和監(jiān)控Java應(yīng)用程序,為Java應(yīng)用提供了一種高效、一致的管理方式,本文就來(lái)介紹一下JMX的使用,感興趣的可以了解一下
    2024-10-10
  • springboot bean掃描路徑的實(shí)現(xiàn)

    springboot bean掃描路徑的實(shí)現(xiàn)

    這篇文章主要介紹了springboot bean掃描路徑的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-01-01
  • 舉例講解Java中do-while語(yǔ)句的使用方法

    舉例講解Java中do-while語(yǔ)句的使用方法

    這篇文章主要介紹了Java中do-while語(yǔ)句的使用方法例子,是Java入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-10-10
  • java DOM4J 讀取XML實(shí)例代碼

    java DOM4J 讀取XML實(shí)例代碼

    最近學(xué)習(xí)Java,在處理XML文檔的時(shí)候,查閱相關(guān)資料,發(fā)現(xiàn)了DOM4J這個(gè)jre庫(kù),相對(duì)C#的XML處理來(lái)說(shuō),功能還算是跟得
    2013-09-09
  • 詳解Mybatis中的 ${} 和 #{}區(qū)別與用法

    詳解Mybatis中的 ${} 和 #{}區(qū)別與用法

    這篇文章主要介紹了Mybatis中的 ${} 和 #{}區(qū)別與用法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • java中String.matches方法使用

    java中String.matches方法使用

    String.matches()方法用于檢測(cè)字符串是否符合特定的正則表達(dá)式,詳細(xì)介紹了如何使用String.matches()配合不同的正則表達(dá)式來(lái)匹配各種特定格式的字符串,感興趣的可以了解一下
    2024-09-09
  • 詳解Maven profile配置管理及激活profile的幾種方式

    詳解Maven profile配置管理及激活profile的幾種方式

    這篇文章主要介紹了詳解Maven profile配置管理及激活profile的幾種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 詳解Java執(zhí)行g(shù)roovy腳本的兩種方式

    詳解Java執(zhí)行g(shù)roovy腳本的兩種方式

    這篇文章主要介紹了Java執(zhí)行g(shù)roovy腳本的兩種方式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • Spring Boot集成Thymeleaf模板引擎的完整步驟

    Spring Boot集成Thymeleaf模板引擎的完整步驟

    這篇文章主要給大家介紹了關(guān)于Spring Boot集成Thymeleaf模板引擎的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Spring Boot實(shí)現(xiàn)郵件服務(wù)(附:常見(jiàn)郵箱的配置)

    Spring Boot實(shí)現(xiàn)郵件服務(wù)(附:常見(jiàn)郵箱的配置)

    這篇文章主要給大家介紹了關(guān)于Spring Boot實(shí)現(xiàn)郵件服務(wù)的相關(guān)資料,文中還附上了常見(jiàn)郵箱的配置,通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12

最新評(píng)論

襄汾县| 北安市| 清水县| 徐汇区| 突泉县| 扶余县| 咸宁市| 五河县| 石城县| 久治县| 洪雅县| 乐都县| 卓尼县| 台东县| 和平区| 五华县| 阿拉善右旗| 漳州市| 隆德县| 黔东| 扶沟县| 阳新县| 陵水| 霍林郭勒市| 本溪市| 台中市| 莱阳市| 海口市| 湘西| 夏河县| 任丘市| 库伦旗| 连云港市| 光山县| 鞍山市| 扬中市| 玉山县| 缙云县| 鸡西市| 涿州市| 旌德县|