本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

SpringBoot3集成Druid时_如何解决Servlet访问问题?

网络教程 app 1℃

SpringBoot3集成Druid时_如何解决Servlet访问问题

springboot 3 中配置 druid 时如何解决无法访问 servlet 问题?

在使用 springboot 3.0.5 集成 druid 1.2.16 时,由于无法访问 javax.servlet.http.httpservlet,导致配置 druid 的 servletregistrationbean 出现错误。

解决方案:

既然使用了 druid-spring-boot-starter,理论上无需过多代码即可完成配置。可参考官方文档:

[druid springboot starter](github./alibaba/druid/tree/master/druid-spring-boot-starter)

也可以通过以下步骤解决:

1. 添加 @ponentscan(“.alibaba.druid”) 注解:

此注释将加载必要的类,但可能会引起异常。

2. 弃用 void org.springframework.boot.web.servlet.filterregistrationbean.setfilter(javax.servlet.filter) 方法:

这是由于 springboot 3 从 java ee 迁移到了 jakarta ee api,导致 servlet 的相关类发生了更改。

3. 在 application.properties 中启用监控页面:

spring.datasource.druid.stat-view-servlet.enabled: true

完成上述步骤后,应能成功配置 druid 并打开其监控页面。

以上就是SpringBoot 3集成Druid时,如何解决Servlet访问问题?的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » SpringBoot3集成Druid时_如何解决Servlet访问问题?

喜欢 (0)