我有一堆模块(比如3)。两个是基于弹簧启动的模块,另一个是基于弹簧的模块。说模块 1 - 弹簧靴模块 2 - 弹簧启动模块 3 - 通用模块仅基于弹簧
模块 3 @Configuration定义的文件,该文件仅需要由模块 2 而不是 1 选取。
我尝试了很多东西来排除配置文件。例如:-
@SpringBootApplication
@ComponentScan(basePackages = {"com.adobe"}
, excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {WorkerConfig.class, WorkerExecutors.class, Worker.class})})
public class Application {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
但是@Configiration类仍然没有被排除在外,Spring正试图在我不想要的应用程序上下文中加载它。我的配置类
@Configuration
public class WorkerConfig {
@Bean
public WorkerExecutors workerExec() {
WorkerExecutors executors = new WorkerExecutors();
return executors;
}
}
我也确实在注释@ComponentScan读到
* <p>Note that the {@code <context:component-scan>} element has an
* {@code annotation-config} attribute; however, this annotation does not. This is because
* in almost all cases when using {@code @ComponentScan}, default annotation config
* processing (e.g. processing {@code @Autowired} and friends) is assumed. Furthermore,
* when using {@link AnnotationConfigApplicationContext}, annotation config processors are
* always registered, meaning that any attempt to disable them at the
* {@code @ComponentScan} level would be ignored.
所以看起来排除在组件扫描不起作用。除此之外,我还尝试排除使用
@SpringBootApplication(exclude= {WorkerExecutors.class, Worker.class,WorkerConfig.class})
public class Application {
但弹簧靴投掷
java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes:
- com.adobe.repository.worker.lib.config.WorkerConfig
- com.adobe.acp.repository.worker.lib.core.WorkerExecutors
- com.adobe.acp.repository.worker.lib.core.Worker
任何想法,我如何禁用组件扫描弹簧启动模块中的非弹簧启动模块,而不是放入不同的包。我不想放入不同的包装。
任何帮助是值得赞赏的!
天涯尽头无女友
喵喔喔
相关分类