Spring引导自动配置尝试从依赖项目加载bean

Spring引导自动配置尝试从依赖项目加载bean,spring,spring-boot,Spring,Spring Boot,Spring Boot正在从外部依赖jar加载bean 如何停止从依赖jar加载Bean的自动配置。 下面是使用的注释 @Configuration @SpringBootApplication(excludeName = {"com.test.core"}) @ComponentScan(basePackages = {"com.test.myhazelcast"}) @EnableJpaRepositories public class BelHazelcastApplication { .

Spring Boot正在从外部依赖jar加载bean

如何停止从依赖jar加载Bean的自动配置。 下面是使用的注释

@Configuration
@SpringBootApplication(excludeName = {"com.test.core"})
@ComponentScan(basePackages = {"com.test.myhazelcast"})
@EnableJpaRepositories
public class BelHazelcastApplication { ...
我希望SpringBoot不要配置任何bean com.test.core.*这是一个依赖模块


但以com.test.myhazelcast.*package中的bean为例。

SpringBootApplication的
excludeName
属性用于按名称排除自动配置类,而不是从组件扫描中排除包

因为您
SpringBootApplication
默认为包到组件扫描,所以它将从BelHazelcastApplication所在的任何包进行组件扫描

如果这个包是“com.test”,那么它将包括“com.test.core”中的组件

我要删除这一行:

@ComponentScan(basePackages = {"com.test.myhazelcast"})
改变这一点:

@SpringBootApplication(excludeName = {"com.test.core"})
将是:

@SpringBootApplication(basePackages = {"com.test.myhazelcast"})

您在com.test.myhazelcast中还有其他@Configuration类吗?