eclipse新建一个springsecurity项目
2016-08-26 09:26
901 查看
eclipse新建一个springsecurity项目
第一步,打开eclipse,点击新建-->web项目
第二步,导入jar包
1. 加入 Spring 的 jar 包2. 加入 SpringSecurity 的 jar 包
spring-security-acl-3.1.0.M1.jar
spring-security-config-3.1.0.M1.jar
spring-security-core-3.1.0.M1.jar
spring-security-taglibs-3.1.0.M1.jar
spring-security-web-3.1.0.M1.jar
第三步,在web.xml中添加contextLoader和springsecurity的配置
<span style="font-size:12px;"> <!-- 配置 ContextLoaderListener 加载applicationContext.xml--> <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> <!-- 配置springsecurity 的filter 其中的helloFilter是spring容器中装配的bean--> <filter> <filter-name>helloFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>helloFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></span>
第四步,在src下新建一个HelloFilter类,实现Filter接口,用于测试
@Component为HelloFilter添加注解,将其注入到spring容器中@Component public class HelloFilter implements Filter{ @Override public void destroy() { // TODO Auto-generated method stub System.out.println("filter destory..."); } @Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { System.out.println("[HelloFilter]doFilter..."); } @Override public void init(FilterConfig arg0) throws ServletException { System.out.println("filter init..."); }
第五步,配置spring的配置文件(eg:applicationContext.xml)
<span style="font-weight: normal;"><p><span style="font-size:18px;"><beans xmlns="http://www.springframework.org/schema/beans" </span></p><p><span style="font-size:18px;"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd 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-4.0.xsd"></span> </p></span>
a),在applicationcontext.xml中添加扫描注解
<span style="font-weight: normal;"><context:component-scan base-package="com.shawsuper.securityfilter.HelloFilter"></context:component-scan></span>
第六步,在eclipse的tomcat上部署运行,当你访问你的项目时,如果控制台控制台输出[HelloFilter]doFilter...即为新建成功
相关文章推荐
- MyEclipse Web Project转Eclipse Dynamic Web Project
- Windows Clang开发环境备忘
- Gradle eclipse plugin how to attach dependency source code
- Gradle eclipse plugin how to attach dependency source code
- 傻瓜式用Eclipse连接MySQL数据库
- Eclipse引入jquery报错如何解决
- 让Flex Builder 3.0与Eclipse3.4整合起来
- Eclipse配置Javascript开发环境图文教程
- 使用zend studio for eclipse不能激活代码提示功能的解决办法
- 图解Eclipse j2ee开发环境的搭建过程
- 两种Eclipse部署动态web项目方法
- ext for eclipse插件安装方法
- 解决Fedora14下eclipse进行android开发,ibus提示没有输入窗口的方法详解
- eclipse导入jquery包后报错的解决方法
- Eclipse 格式化代码时不换行与自动换行的实现方法
- Eclipse下jQuery文件报错出现错误提示红叉
- eclipse如何忽略js文件报错(附图)
- eclipse3.2.2 + MyEclipse5.5 + Tomcat5.5.27 配置数据库连接池
- jquery库或JS文件在eclipse下报错问题解决方法
- 什么是eclipse,eclipse的意思解析