版本:

        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. 安装ThinkPHP

    ThinkPHP5的环境要求如下: PHP >= 5.4.0 PDO PHP Extension MBstring PHP Extension CURL PHP Extension 严格来说,T ...

  2. 【LeetCode 84】柱状图中最大的矩形

    题目链接 [题解] 维护一个单调递增的栈. 会发现栈内的第i个元素的前面一个(i-1)元素在原始的序列中的数字 都是要高于第i个元素的.(或者没有元素) 那么第i个元素往左最多可以扩展到第i-1个元素 ...

  3. 线性规划(Simplex单纯形)与对偶问题

    线性规划 首先一般所有的线性规划问题我们都可以转换成如下标准型: 但是我们可以发现上面都是不等式,而我们计算中更希望是等式,所以我们引入这个新的概念:松弛型: 很显然我们最后要求是所有的约束左边的变量 ...

  4. 汉诺塔IX

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=76447#problem/E 汉诺塔IX Time Limit:1000MS     Me ...

  5. yarn 国内加速,修改镜像源

    为什么慢 由于默认情况下执行 yarn 各种命令是去国外的 yarn 官方镜像源获取需要安装的具体软件信息,所以在不使用代理.不翻墙的情况下,从国内访问国外服务器的速度相对比较慢 可以通过以下命令快速 ...

  6. row_number() over partition by 分组聚合

    分组聚合,就是先分组再排序,可以的话顺手标个排名:如果不想分组也可以排名:如果不想分组同时再去重排名也可以 ROW_NUMBER() OVER( [PARTITION BY column_1, col ...

  7. HttpServletRequest 对文件上传的支持

    此前,对于处理上传文件的操作一直是让开发者头疼的问题,因为 Servlet 本身没有对此提供直接的支持,需要使用第三方框架来实现,而且使用起来也不够简单.Servlet 3.0 已经提供了这个功能,而 ...

  8. 《单词的减法》state1~state17(第三遍学习记录)

    2016.05.24 state 8 curse/curve dedication 多用于奉献和献身 disastrous disruptive distract state 9 domestic/d ...

  9. Bootstrap+Ajax+HTML 动态表格分页

      1.HTML页面:(bootstrap的模态框) 触发模态框: <div class="col-lg-6"> <div class="input-g ...

  10. PAT甲级【2019年9月考题】——A1162 MergingLinkedLists【25】

    7-2 Merging Linked Lists (25 分) Given two singly linked lists L 1 =a 1 →a 2 →...→a n−1 →a n  L1=a1→a ...