版本:

        spring boot 2.1.2.RELEASE

        druid-spring-boot-starter 1.1.13

步骤:  

     一.maven        

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
...
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.13</version>
</dependency>

  二、yml配置

spring:
profiles: dev
datasource:
url: jdbc:mysql://127.0.0.1:3306/sina?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
name: druidDataSource
type: com.alibaba.druid.pool.DruidDataSource
# driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
druid:
#初始化大小,最小,最大
initial-size: 5
min-idle: 5
max-active: 20
#配置获取连接等待超时的时间
max-wait: 60000
#配置多久检测一次,检测需要关闭空间连接,单位ms
time-between-eviction-runs-millis: 60000
# 配置一个池中最小生存的时间
min-evictable-idle-time-millis: 300000
#用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用
validation-query: SELECT 1 FROM DUAL
#建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
test-while-idle: true
#申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
test-on-borrow: false
#归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
test-on-return: false
#要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
max-pool-prepared-statement-per-connection-size: 20
#属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:
#监控统计用的filter:stat
#日志用的filter:log4j
#防御sql注入的filter:wall
filters: stat,wall
#合并多个DruidDataSource的监控数据
use-global-data-source-stat: true
#通过connectProperties属性打开mergeSql功能;慢sql记录
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 配置监控服务器
stat-view-servlet:
login-username: admin
login-password: 123456
url-pattern: /druid/*
#添加ip白名单
allow: 127.0.0.1,192.168.0.5
#黑名单,黑白名单有重复,黑优先级高
#deny:
# 禁用HTML页面上的“Reset All”功能
reset-enable: false
# 必须启用,要不会404
enabled: true
web-stat-filter:
#添加过滤规则
url-pattern: /*
#忽略过滤格式
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico"
enabled: true
async-close-connection-enable: true
aop-patterns: com.sswchat.service.*
filter:
stat:
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
enabled: true jpa:
show-sql: true
hibernate:
ddl-auto: create-drop

我的环境在不加enable:true时访问http://127.0.0.1:8080/druid/login.html会报404

三、Security的SecurityConfig配置文件

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/sign", "/druid/**");
} @Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
//.antMatchers("/css/**","/sign","/druid/**").permitAll()// 与/ css / **和/ index匹配的请求是完全可访问的
.antMatchers("/user/**").hasRole("USER")//与/ user / **匹配的请求要求用户进行身份验证,并且必须与USER角色相关联
.and().formLogin().loginPage("/login")
.failureUrl("/login-error")// 使用自定义登录页面和失败URL启用基于表单的身份验证
.and().csrf().disable();
}
}

配置好后,如果只重写configure(HttpSecurity http),会出现submitlogin 403错误。

spring boot2.x集成spring security5与druid1.1.13(一)的更多相关文章

  1. Spring Boot2.0使用Spring Security

     一.Spring Secutity简介     Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性 ...

  2. Spring Boot中集成Spring Security 专题

    check to see if spring security is applied that the appropriate resources are permitted: @Configurat ...

  3. spring-boot-starter-security Spring Boot中集成Spring Security

    spring security是springboot支持的权限控制系统. security.basic.authorize-mode 要使用权限控制模式. security.basic.enabled ...

  4. spring boot 2.0(一)权威发布spring boot2.0

    Spring Boot2.0.0.RELEASE正式发布,在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误,然后Spring ...

  5. Spring Boot2.0之整合事物管理

    首先Spring 事务分类 1.声明事务  原理:基于编程事务的 2.编程事务  指定范围 扫包去解决 3.事务原理:AOP技术   通过环绕通知进行了拦截 使用Spring 事务注意事项: 不要tr ...

  6. Spring Boot2+Resilience4j实现容错之Bulkhead

    Resilience4j是一个轻量级.易于使用的容错库,其灵感来自Netflix Hystrix,但专为Java 8和函数式编程设计.轻量级,因为库只使用Vavr,它没有任何其他外部库依赖项.相比之下 ...

  7. SpringMVC 3.1集成Spring Security 3.1

    这篇算是一个入门文章,昨天看见有网友提问,spring mvc集成spring security 的时候出错,揣测了一下问题木有解决.我就帮忙给搭建了一个集成框架他说可以,他告诉我这样的文章网上少.今 ...

  8. 细说shiro之五:在spring框架中集成shiro

    官网:https://shiro.apache.org/ 1. 下载在Maven项目中的依赖配置如下: <!-- shiro配置 --> <dependency> <gr ...

  9. Spring MVC集成Spring Data Reids和Spring Session实现Session共享

    说明:Spring MVC中集成Spring Data Redis和Spring Session时版本是一个坑点,比如最新版本的Spring Data Redis已经不包含Jedis了,需要自行引入. ...

随机推荐

  1. .Net Core 使用 Swagger 提供API文档

    1.运行环境 开发工具:Visual Studio 2017 JDK版本:.NET Core 2.0 项目管理工具:nuget 2.GITHUB地址 https://github.com/nbfujx ...

  2. spring-cloud:eureka server单机、双机、集群示例

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springCl ...

  3. 4412 Linux定时器

    一.Linux定时器基础知识 1.1 定时器的使用范围 延后执行某个操作,定时查询某个状态:前提是对时间要求不高的地方 1.2 内核时间概念 Hz:(系统时钟通过CONFIG_HZ来设置,范围是100 ...

  4. AGC013 E Placing Squares——模型转化+矩阵乘法

    题目:https://atcoder.jp/contests/agc013/tasks/agc013_e 边长的平方,可以看做是在该范围内放两个不同的球的方案数.两个球可以重合. 题意变成:给长为 n ...

  5. PWN入门的入门——工具安装

    安装pwntool: 命令行运行: pip install pwntools python import pwn pwn.asm("xor eax,eax") 出现'1\xc0'  ...

  6. 学会如何使用,pycharm,和gitlanb

    好好看,好好学.这才是正确的. 1  在pycharm 里面选择checkout as  切换分支 2    选择自己提交的,然后选择审核人.是强哥

  7. 1.OpenCV数据类型

    基础类型 1.模板类cv::Vec<> 固定向量类,维度已知的小型向量——处理效率高 2.cv::Point类(Point2i,Point2f,Point2d;Point3i,Point3 ...

  8. js判断客户端是pc还是移动端

    navigator.userAgentNavigator 对象包含有关浏览器的信息.没有应用于 navigator 对象的公开标准,不过所有浏览器都支持该对象.userAgent 属性是一个只读的字符 ...

  9. JDK1.8 - > 1.7

    原文地址  https://blog.csdn.net/hwjean/article/details/52537722 JDK 1.8 -> 1.7 1. 配置好环境变量(我的是64bit系统) ...

  10. HDU 5183 Negative and Positive (NP) (手写哈希)

    题目链接:HDU 5183 Problem Description When given an array \((a_0,a_1,a_2,⋯a_{n−1})\) and an integer \(K\ ...