博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringSecurity入门使用(手把手创建项目带你入门)
阅读量:3959 次
发布时间:2019-05-24

本文共 3567 字,大约阅读时间需要 11 分钟。

SpringSecurity入门使用

一.创建工程

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
目录结构如下(下面resources目录没有,需要自己加上):
在这里插入图片描述

二.文件配置

1.在pom.xml文件里面加上下面这段代码:

5.0.2.RELEASE
5.0.1.RELEASE
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-test
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework.security
spring-security-web
${spring.security.version}
org.springframework.security
spring-security-config
${spring.security.version}
javax.servlet
javax.servlet-api
3.1.0
provided
org.apache.maven.plugins
maven-compiler-plugin
3.2
1.8
1.8
UTF-8
org.apache.tomcat.maven
tomcat7-maven-plugin
8090
/

pom.xml文件的内容都是比较死的,没什么逻辑可以讲解,这里大家直接copy就可以了。

2.web.xml文件内容:

SpringSecurity314
contextConfigLocation
classpath:spring-security.xml
org.springframework.web.context.ContextLoaderListener
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp

3.在resources目录下面的spring-security.xml内容如下:

我们从上面的注释可以知道

/**将会拦截一切路径,如果访问者有ROLE_USER权限才可以通过
这里是定义用户user,其密码是user前面的{noop}是一种固定的写法,ROLE_USER是权限
这一配置会帮我们默认生成login.html页面

访问:http://localhost:8090/(访问后网址会自动变为http://localhost:8090/login)来到下面页面

在这里插入图片描述

三.使用自己的页面跳转

login.html:

    
Insert title here
用户名:
密码:

failer.html:

    
Insert title here登录失败

success.html:

    
Insert title heresuccess html
退出

spring-security.xml文件内容如下:

接下来我们的入门项目就全部解决好了,演示就交给大家吧

转载地址:http://volzi.baihongyu.com/

你可能感兴趣的文章