在我的spring boot项目中,我必须使用一个外部库,它在spring上下文中定义了bean。因此,在我的Application类中,我在下面添加了我的项目和外部库的基包,
@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没有初始化吗?
发布于 2016-01-26 20:49:13
@ComponentScan适用于使用@Component、@Repository或@Service注释的类。确保"com.otherlibrary.springtool“中的类使用上面的注释进行注释,否则您必须使用@Bean注释将它们声明为Spring Bean。希望能有所帮助。
发布于 2021-05-10 22:12:33
当我试图使用来自外部库的开放feign接口时,我也遇到了类似的情况,然后我不得不添加@EnableFeignClients(basePackages = {"lib.pckg"}),因为Feign必须为我创建IoC,而不是Spring bean。
如果你提供一些日志错误,那就更好了。
https://stackoverflow.com/questions/34989099
复制相似问题