[alibaba/druid]druid-boot3 1.2.20版本无法打开监控

2023-12-09 716 views
3

当配置 stat-view-servlet: enabled: true 启动项目会报错: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/*]}.改为false就可以正常启动

回答

8

我昨天也发现了这个问题。环境是 springboot3.1.3, springwebsecurity, druid-boot3 1.2.20 。

1

误诊了, springboot3.1.3 和 druid-boot3 1.2.20 没有问题,能出来监控页面。问题发现是出在 spring web security 身上,当要配置具体的匿名可访问页面时,就会出现楼上说的问题,当你不指定具体页面,全部可匿名访问,例如: auth.anyRequest().permitAll(),就OK了。 要解决:再搞搞spring web security , 解决 MvcRequestMatcher 和 request mapping 分流 DispatcherServlet StatViewServlet ;

7

springboot3.1.4开始才有这个问题 在spring security的配置中 requestMatchers配置的资源路径需要指明AntPathRequestMatcher还是MvcRequestMatcher; 在我的场景中我需要的是AntPathRequestMatcher: import static org.springframework.security.web.util.matcher.AntPathRequestMatcher.antMatcher; 资源路径都用antMatcher包起来了,如:antMatcher("/druid/**")

8

老哥说的对,给过滤链加上一句 .requestMatchers(new MvcRequestMatcher(handlerMappingIntrospector, "/druid/**")).permitAll() 就ok了