本文源代码下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2015年资料/1月/22日/Spring Security身份认证之HelloSpringSecurity(附源码)
------------------------------------------分割线------------------------------------------
开发环境如下:
项目目录结构如下:

1.新建Maven Project,对Maven不熟悉的童鞋请自行充电,现在这个念头不学习Maven绝对是不行的。

2. 在Pom.xml添加相关jar依赖。
?
?
?
?
?
?
?
? ?
? ?
? ? ? ? ?
?
? ?
?
? ?
? ? ?
? ? ?
? ? ?
? ? ?
? ?
? ? ?
? ? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ? ?
? ? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ?
? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ?
? ? ? ?
? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ?
?
?
? ?
?
3. 配置web.xml,在容器启动时加载Spring MVC的配置文件与Spring Security的配置文件。
? ? xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
? ?
? ? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ? ? ? classpath:springSecurity.xml
? ? ? ?
? ?
? ? ?
? ?
? ? ? ?
? ?
? ? ?
? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ?
? ? ?
? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ?
? ? ? ?
? ?
? ?
? ? ? ?
? ? ? ?
? ?
?
4. SpringSecurity.xml配置文件如下
? ? xmlns:security="http://www.springframework.org/schema/security"
? ? xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
? ? ? ? http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">
?
? ?
? ? ? ?
? ? ? ?
? ?
? ? ?
? ? ?
? ?
? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ?
? ?
? ? ?
5.spring-context.xml配置文件如下
? ? xmlns:context="http://www.springframework.org/schema/context"
? ? xmlns:mvc="http://www.springframework.org/schema/mvc"
? ? 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-3.2.xsd
? ? ? ? http://w