【发布时间】:2016-05-01 13:20:13
【问题描述】:
在我的 spring boot 项目中,我必须使用一个外部库,它在 spring 上下文中定义了 beans。所以在我的应用程序类中,我在下面添加了我的项目和外部库的基础包,
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@EnableHypermediaSupport(type = { EnableHypermediaSupport.HypermediaType.HAL })
@EnableSwagger2
@ComponentScan(basePackages = {"com.mylibrary.test", "com.otherlibrary.springtool"})
//@EnableDiscoveryClient
public class Application extends RepositoryRestMvcConfiguration {
}
但是@Configuration等其他库中的bean没有初始化?
【问题讨论】:
-
你在哪里添加了这个
@ComponentScan?这甚至被扫描了吗? -
@M.Deinum 我已经编辑了问题
-
该配置对我来说看起来不错。您可能想使用
basePackageClasses来消除包名称中出现拼写错误的可能性。此外,如果您使用的是 Spring Boot 1.3,您可以将包配置为直接扫描SpringBootApplication并避免额外的注释 -
我也有同样的问题,好像库中包含的“@Configuration”中的“@ComponentScan”,其基本包与调用者的不同,不扫描任何东西
标签: java spring spring-boot