---
title: "spring-security3 配置和使用."
author: "hyperprice"
date: "2010-06-22T16:37:21Z"
tags: ["JSP", "Security", "Spring", "XML", "配置管理"]
categories: ["企业架构"]
slug: "spring-security3"
draft: false
lastmod: "2010-06-22T16:37:21Z"
id: 696645
url: "https://xuxn.iteye.com/blog/696645"
---

刚才想发到论坛来的.. 结果使用的是chrome打完字没注意就点了发布.. T\_T. 最近项目中要使用到spring-security，闲来没事就研究了下。发现入门挺简单的，在这里把自己的心得发下，希望对没有接触过想接触的朋友有帮助。 1、在spring-security官网下载最新jar然后拷贝jar到项目的lib下。 2、在classpath下添加security配置文件,例如applicationContext-security.xml.网上现在大多都是2.0的schema. 要根据自己使用的版本而定.下面是3.0的schema. \[code="xml"] \[/code] 3、然后在web.xml中添加配置,内容如下: \[code="xml"] contextConfigLocation classpath\*:/applicationContext\*.xml springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /* org.springframework.web.context.ContextLoaderListener \[/code] 配置起来很简单,由于我的security是整合到现有项目中的.一些jar可能已经存在. 单独做demo的朋友配置的时候可能会出现问题. 本想分开发挣点积分..但怕大家看起来累.. 就发到一起吧.. (\*^\_\_^\*) 使用篇 1、建立login.jsp页面.内容如下: \[code="html"]

USERNAME:  
PASSWORD:  
两周之内不必登陆

\[/code] j\_spring\_security\_check : 为security验证中心(不知道怎么说合适.暂时这么理解吧..). j\_username: 验证用户名; j\_password: 验证密码; ${sessionScope\['SPRING\_SECURITY\_LAST\_USERNAME']}:使用最后一次登录用户名. \_spring\_security\_remember\_me:记住我... 2、xml配置,配置内容如下: \[code="xml"] \[/code] 以上配置结束后可以完成用户登录\\权限验证等操作. 配置和使用到这里就结束了. 今天下午的小心得.. spring-security很强大. 在这里感谢family168的在线帮助. 谢谢.. 希望对没有接触过spring-security的朋友有所帮助.