工具包自动扫描解决方法"/>
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 第三方工具包自动扫描解决方法
发布评论