MyException - 我的异常网
当前位置:我的异常网» 编程 » Spring Security 学习(一)

Spring Security 学习(一)

www.MyException.Cn  网友分享于:2013-02-21  浏览:13次
Spring Security 学习(1)

使用 MyEclipse 10.0 搭建环境

1.创建 Web 项目 spring_security

2.添加spring 相关支持.如下图:


 
 
3.手动下载org.springframework.transaction-3.0.0.RELEASE.jar 并导入 其工程
未导入该jar包 启动Tomcat 将抛出 org/springframework/dao/DataAccessException   是个很诡异的异常.
下载地址: http://www.java2s.com/Code/Jar/o/Downloadorgspringframeworktransaction300RELEASEjar.htm

4。配置 .
     4.1 web.xml 

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	<display-name></display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

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

	<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>

 
    4.2  applicationContext.xml

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

	<security:http auto-config="true">
		<security:intercept-url pattern="/**" access="ROLE_USER" />
	</security:http>

	<!--配置认证管理器 -->
	<security:authentication-manager>
		<security:authentication-provider>
			<security:user-service>
				<security:user name="user" password="user"
					authorities="ROLE_USER" />
			</security:user-service>
		</security:authentication-provider>
	</security:authentication-manager>

</beans>

 
5.部署应用  到现在为止 就完成了一个最为简单 SpringSecurity 应用的小例子 .

 

 

 

 

 

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有