【MAVEN】exclusions 排除依赖不生效
AI-摘要
秃佬 GPT
AI初始化中...
介绍自己
生成本文简介
推荐相关文章
前往主页
前往tianli博客
最近升级jdk21+springboot3写基础组件时,碰到druid监控页面配置失效启动会报错:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statViewServlet' defined in com.shunyu.dma.iot.center.RunApplication: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method 'statViewServlet' threw exception with message: class com.alibaba.druid.support.http.StatViewServlet cannot be cast to class jakarta.servlet.Servlet (com.alibaba.druid.support.http.StatViewServlet and jakarta.servlet.Servlet are in unnamed module of loader 'app')
由于使用的是springboot3
出现这个启动报错
SpringBoot切换了一些版本依赖,将javax切换到了jakarta
https://github.com/alibaba/druid/issues/5022
由于druid-spring-boot-3-starter的1.2.23版本内部使用的是druid的1.2.15版本,这个版本没兼容jakarta
<!--Druid Spring Boot 组件-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<version>1.2.23</version>
<exclusions>
<exclusion>
<artifactId>druid</artifactId>
<groupId>com.alibaba</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.23</version>
</dependency>
import com.alibaba.druid.support.jakarta.StatViewServlet;
@Bean
public ServletRegistrationBean statViewServlet(){
StatViewServlet statViewServlet = new StatViewServlet();
ServletRegistrationBean<StatViewServlet> statViewServletServletRegistrationBean = new ServletRegistrationBean<StatViewServlet>(statViewServlet, "/druid/*");
return statViewServletServletRegistrationBean;
}
maven父子依赖传递问题
基础组件父pom定义了版本,虽然上面排除了, 但是还是会被固定, 所以注释或者重新指定版本即可
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 程序员小航
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果