开发环境

配置spring mvc + spring security
pom.xml
<properties>
<spring.version>4.3.8.RELEASE</spring.version>
<spring-sercurity.version>4.2.2.RELEASE</spring-sercurity.version>
</properties>
<dependencies>
<!-- Spring 4 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-sercurity.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-sercurity.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring-sercurity.version}</version>
</dependency>
</dependencies>
spring mvc 使用的是4.3.8版本,spring security 使用的是4.2.2版本。
spring-mvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="com.controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true" >
<intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="123456" authorities="ROLE_USER"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Archetype Created Web Application</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring-mvc-servlet.xml, classpath:spring-security.xml </param-value> </context-param> <!-- spring mvc --> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring-mvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- spring security --> <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>
测试
spring会拦截所有请求,如果没有登录,则系统会跳转到spring security默认的登录页面。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# spring
# security
# 配置
# Spring Boot Security 结合 JWT 实现无状态的分布式API接口
# spring security动态配置url权限的2种实现方法
# SpringBoot + Spring Security 基本使用及个性化登录配置详解
# spring security国际化及UserCache的配置和使用
# 详解spring security 配置多个AuthenticationProvider
# spring security在分布式项目下的配置方法(案例详解)
# 的是
# 如果没有
# 大家多多
# 跳转到
# servlet
# config
# UTF
# encoding
# web
# artifactId
# springframework
# org
# context
# core
相关文章:
制作网站的软件免费下载,免费制作app哪个平台好?
专业的网站制作设计是什么,如何制作一个企业网站,建设网站的基本步骤有哪些?
网站专业制作公司有哪些,做一个公司网站要多少钱?
官网自助建站系统:SEO优化+多语言支持,快速搭建专业网站
建站OpenVZ教程与优化策略:配置指南与性能提升
制作门户网站的参考文献在哪,小说网站怎么建立?
免费公司网站制作软件,如何申请免费主页空间做自己的网站?
整蛊网站制作软件,手机不停的收到各种网站的验证码短信,是手机病毒还是人为恶搞?有这种手机病毒吗?
儿童网站界面设计图片,中国少年儿童教育网站-怎么去注册?
简历在线制作网站免费,免费下载个人简历的网站是哪些?
如何自定义建站之星模板颜色并下载新样式?
制作网页的网站有哪些,电脑上怎么做网页?
如何确保FTP站点访问权限与数据传输安全?
logo在线制作免费网站在线制作好吗,DW网页制作时,如何在网页标题前加上logo?
如何用wdcp快速搭建高效网站?
手机网站制作平台,手机靓号代理商怎么制作属于自己的手机靓号网站?
英语简历制作免费网站推荐,如何将简历翻译成英文?
网站代码制作软件有哪些,如何生成自己网站的代码?
建站与域名管理如何高效结合?
制作电商网页,电商供应链怎么做?
如何在搬瓦工VPS快速搭建网站?
如何在Golang中指定模块版本_使用go.mod控制版本号
如何选择高效响应式自助建站源码系统?
如何选择高效稳定的ISP建站解决方案?
建站主机核心功能解析:服务器选择与网站搭建流程指南
建站之星图片链接生成指南:自助建站与智能设计教程
php条件判断怎么写_ifelse和switchcase的使用区别【对比】
建站为何优先选择香港服务器?
建站之星如何快速解决建站难题?
如何在阿里云香港服务器快速搭建网站?
如何制作网站标识牌,动态网站如何制作(教程)?
nginx修改上传文件大小限制的方法
香港服务器WordPress建站指南:SEO优化与高效部署策略
如何在阿里云通过域名搭建网站?
建站之星收费标准详解:套餐费用及年费价格表一览
实现点击下箭头变上箭头来回切换的两种方法【推荐】
如何通过wdcp面板快速创建网站?
打鱼网站制作软件,波克捕鱼官方号怎么注册?
如何在阿里云完成域名注册与建站?
青岛网站建设如何选择本地服务器?
寿县云建站:智能SEO优化与多行业模板快速上线指南
如何快速搭建个人网站并优化SEO?
外贸公司网站制作,外贸网站建设一般有哪些步骤?
如何获取PHP WAP自助建站系统源码?
如何选择服务器才能高效搭建专属网站?
建站之星客服服务时间及联系方式如何?
如何优化Golang Web性能_Golang HTTP服务器性能提升方法
企业在线网站设计制作流程,想建设一个属于自己的企业网站,该如何去做?
建站之星如何实现PC+手机+微信网站五合一建站?
免费制作小说封面的网站有哪些,怎么接网站批量的封面单?
*请认真填写需求信息,我们会在24小时内与您取得联系。