版本:

        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. 【Java】字符串转json

    import org.json.JSONObject; JSONObject jo = new JSONObject(new String(需要转换的字符串));

  2. 【Linux】清理缓存buffer/cache

    运行sync将dirty的内容写回硬盘 sync 通过修改proc系统的drop_caches清理free的cache echo 3 > /proc/sys/vm/drop_caches ech ...

  3. iptables防火墙相关命令详解

    前提基础: 当主机收到一个数据包后,数据包先在内核空间中处理,若发现目的地址是自身,则传到用户空间中交给对应的应用程序处理,若发现目的不是自身,则会将包丢弃或进行转发. iptables实现防火墙功能 ...

  4. KVM(多电脑切换器)

    KVM:Keyboard Video Mouse的缩写.KVM 交换机通过直接连接键盘.视频和鼠标 (KVM) 端口,让您能够访问和控制计算机.KVM 技术无需目标服务器修改软件.这就意味着可以在 W ...

  5. [CSP-S模拟测试]:randomwalking(DP)

    题目传送门(内部题59) 输入格式 第一行一个数$n$表示点数.第二行$n$个数$A_i$.接下来$n−1$行,每行两个数$u,v$表示$u$和$v$有边直接相连. 输出格式 一个数表示最小花费的起点 ...

  6. Cent OS (二)常用的命令介绍

    1. 常用的Linux命令   序号 命令 对应英文 作用 01 ls list 查看当前文件夹下的内容 02 pwd print work directory 查看当前所在的文件夹 03 cd [目 ...

  7. Castle动态代理拦截

    比如现在有一个方法,进行积分奖励 PointAdd 在不改变原来方法的基础上,增加积分奖励的日志 using Castle.DynamicProxy; public class AuditTraceI ...

  8. selenium2-java 浏览器操作常用命令语法

    WebDriver driver = new ChromeDriver(); xpath定位:driver.findElement(By.xpath("//div[@id='register ...

  9. 多级xml解析方案

    package com.people.xmlToSql; import java.io.File; import java.io.IOException; import java.io.StringW ...

  10. 记录一些比较长的adb命令,复制用

    adb shell content query --uri content://settings/secure --projection value --where "name=\'andr ...