Springboot 第三方工具包自动扫描解决方法

编程入门 行业动态 更新时间:2024-10-22 05:18:20

Springboot 第三方<a href=https://www.elefans.com/category/jswz/34/1753192.html style=工具包自动扫描解决方法"/>

Springboot 第三方工具包自动扫描解决方法

在采用Springboot开发项目时,遇到引用第三方包,需要将其导入到spring容器中,处理方法如下:

1、通过在Application启动类头上加入

@SpringBootApplication
@ComponentScan(basePackages={xxxx.xxx.xx包名})

2、自定义Springboot starter机制

实现式在maven pom.xml 中引入starter包

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
   </dependency>

配置config 

@Configuration
@ComponentScan(basePackages = {"xxx.xxx.xx"})
public class AppConfig{
}
在resourse文件下建立一个

META-INF下,配置spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=xxxx.config.AppConfig

在引用方式直接引用包,不需要@ComponentScan(basePackages={xxxx.xxx.xx包名})

方便的同学,可以自行试试。

更多推荐

Springboot 第三方工具包自动扫描解决方法

本文发布于:2024-02-05 11:30:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1745186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具包   第三方   解决方法   Springboot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!