@ComponentScan 在外部库上不起作用

Har*_*ana 7 java spring spring-boot

在我的 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 {
}
Run Code Online (Sandbox Code Playgroud)

但是其他库(例如@Configuration)中的bean没有初始化?

xaf*_*arr 2

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