当前位置: 首页 > news >正文

springboot3+springsecurity6集成druid启动报错

环境:springboot3+security6+druid1.2.20

druid1.2.20这个版本开始支持springboot3自动配置,不再需要手动引入

依赖为

<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-3-starter</artifactId><version>1.2.20</version>
</dependency>

报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filterChain' defined in class path resource [com/free/security/SecurityConfiguration.class]: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'filterChain' threw exception with message: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).

This is because there is more than one mappable servlet in your servlet context: {org.springframework.web.servlet.DispatcherServlet=[/], com.alibaba.druid.support.jakarta.StatViewServlet=[/druid/*]}.

For each MvcRequestMatcher, call MvcRequestMatcher#setServletPath to indicate the servlet path.

原因:

看报错位置加粗内容是重点

意思是 对于每一个接口,security无法确定这个接口是不是mvc接口,请开发者明确的声明这个接口为MvcRequestMatcher或者AntPathRequestMatcher

看代码,在security配置放行接口的位置,配置了放行druid接口

httpSecurity.authorizeHttpRequests(auth -> auth.requestMatchers("/druid/**").permitAll());

这样的写法是不对的,应该明确的声明这个pattern是哪种pattern,改为

.requestMatchers(AntPathRequestMatcher.antMatcher("/druid/**")).permitAll()

再次启动项目,不再报错

结论:问题并不是因为druid产生的,而是security配置类代码不够严谨

http://www.lryc.cn/news/283489.html

相关文章:

  • golang面试题大全
  • Google 在裁员的路上一路狂奔
  • 橘子学K8S04之重新认识Docker容器
  • Day31- 贪心算法part05
  • 基于springboot+vue的蜗牛兼职网的设计与实现系统(前后端分离)
  • 【音视频原理】图像相关概念 ② ( 帧率 | 常见帧率标准 | 码率 | 码率单位 )
  • CSS Position总结:定位属性的实战技巧
  • python基础系列二-函数
  • Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用短曝光功能(C#)
  • 提升开发效率,Fiddler Everywhere for Mac助您解决网络调试难题
  • JVM工作原理与实战(十九):运行时数据区-方法区
  • webassembly003 whisper.cpp的项目结构CMakeLists.txt
  • 克魔助手工具详解、数据包抓取分析、使用教程
  • 【Docker】contos7安装 Nacos容器部署单个部署集群
  • UML-通信图和交互概览图(通信图和顺序图的区别与联系)
  • Linux 使用PS命令掌握进程管理
  • Debian 10.13.0 安装图解
  • SQLite 3.45.0 发布!
  • MongoDB聚合:$set
  • 《Python数据分析技术栈》第01章 02 Jupyter入门(Getting started with Jupyter notebooks)
  • 【征服redis5】redis的Redisson客户端
  • React16源码: React中的beginWork的源码实现
  • 5-微信小程序语法参考
  • 数组练习 Leetcode 566.重塑矩阵
  • Linux centos中find命令的多种用途:按照具体应用来详细说明find的用法举例
  • 服务器数据恢复—OceanStor存储raid5热备盘同步数据失败的数据恢复案例
  • Xline v0.6.1: 一个用于元数据管理的分布式KV存储
  • 【CSS】解决height = line-height 文字不垂直居中(偏上、偏下)的问题
  • 天津想转行学python培训班靠谱吗?
  • (C语言)冒泡排序