首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@ComponentScan on external library不工作

@ComponentScan on external library不工作
EN

Stack Overflow用户
提问于 2016-01-25 17:30:37
回答 2查看 5.4K关注 0票数 4

在我的spring boot项目中,我必须使用一个外部库,它在spring上下文中定义了bean。因此,在我的Application类中,我在下面添加了我的项目和外部库的基包,

代码语言:javascript
复制
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@EnableHypermediaSupport(type = { EnableHypermediaSupport.HypermediaType.HAL })
@EnableSwagger2
@ComponentScan(basePackages = {"com.mylibrary.test", "com.otherlibrary.springtool"})
//@EnableDiscoveryClient
public class Application extends RepositoryRestMvcConfiguration {
}

但是其他库中的bean,比如@Configuration没有初始化吗?

EN

回答 2

Stack Overflow用户

发布于 2016-01-26 20:49:13

@ComponentScan适用于使用@Component、@Repository或@Service注释的类。确保"com.otherlibrary.springtool“中的类使用上面的注释进行注释,否则您必须使用@Bean注释将它们声明为Spring Bean。希望能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2021-05-10 22:12:33

当我试图使用来自外部库的开放feign接口时,我也遇到了类似的情况,然后我不得不添加@EnableFeignClients(basePackages = {"lib.pckg"}),因为Feign必须为我创建IoC,而不是Spring bean。

如果你提供一些日志错误,那就更好了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34989099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档