当前位置:
首页 > Java技术> Spring>文章信息
Spring+Spring Security+Maven 实现的一个Hello World例子译
[微博]发布于 9 个月前阅读:2466次
[导读]Spring Security允许开发人员轻松地将安全功能集成到J2EE Web应用程序中,它通过Servlet过滤器实现“用户自定义”安全检查。在本教程中,我们将向您展示如何在Spring MVC中集成Spring Security 3.0并安全访问。在集成成功后,当我们查看页面的内容时用户需要先输入正确的“用户名”和“密码”。本教程的开发环境为:1.Spring 3.0.5.RELEASE2.... Spring Security允许开发人员轻松地将安全功能集成到J2EE Web应用程序中,它通过Servlet过滤器实现“用户自定义”安全检查。
在本教程中,我们将向您展示如何在Spring MVC中集成Spring Security 3.0并安全访问。在集成成功后,当我们查看页面的内容时用户需要先输入正确的“用户名”和“密码”。 本教程的开发环境为: 1.Spring 3.0.5.RELEASE
2.Spring Security 3.0.5.RELEASE 3.Eclipse 3.6 4.JDK 1.6 5.Maven 3
注意:Spring Security 3.0 至少需要java 5.0或更高的运行环境。
1.目录结构 本教程的最终目录如下所示: 2.Spring Security依赖关系 为了正常运行 Spring security 3.0, 你需要加入 “spring-security-core.jar“, “spring-security-web.jar” and “spring-security-config.jar“. 在Maven库中你需要加入Spring配置库 pom.xml 3.0.5.RELEASE org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-webmvc ${spring.version} org.springframework.security spring-security-core ${spring.version} org.springframework.security spring-security-web ${spring.version} org.springframework.security spring-security-config ${spring.version} 3.Spring MVC Web应用程序 本教程是一个简单的Spring MVC 应用程序,即访问“/welcome”跳转到“hello.jsp”页面,稍后用Spring Security安全访问这个链接。 HelloController.java package com.mkyong.common.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping(\ public class HelloController { @RequestMapping(method = RequestMethod.GET) public String printWelcome(ModelMap model) { model.addAttribute(\ return \ } } hello.jsp
Message : ${message}
mvc-dispatcher-servlet.xml