<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <!--以下頁面不攔截 這里面的配置沒有權限也能訪問資源--> <http pattern="/login.html" security="none"/> <http pattern="/login_error.html" security="none"/> <!-- 頁面攔截規則 use-expressions禁用spel表達式 access訪問這個路徑的權限 寫法必須以ROLE開頭 后邊跟大寫字母--> <http use-expressions="false"> <intercept-url pattern="/**" access="ROLE_USER"/> <!--login-page指定登陸頁面 default-target-url指定登陸成功后默認的頁面 authentication-failure-url登陸失敗后默認的頁面--> <form-login login-page="/login.html" default-target-url="/index.html" authentication-failure-url="/login_error.html" /> <!--跨域訪問禁用--> <csrf disabled="true"/> </http> <!--認證管理器--> <authentication-manager> <authentication-provider> <user-service> <user name="admin" password="123456" authorities="ROLE_USER"/> </user-service> </authentication-provider> </authentication-manager> </beans:beans>