简体   繁体   English

Spring 启动应用程序忽略导入的配置

[英]Spring boot application ignores imported configuration

To be able to test certain aspects of my application I created this test setup.为了能够测试我的应用程序的某些方面,我创建了这个测试设置。 As I need a custom implementation of the ApplicationContext , it can't be done with a classic SpringBootTest annotation, instead I have this initialisazion:因为我需要ApplicationContext的自定义实现,所以不能用经典的SpringBootTest注释来完成,而是我有这个初始化:

public class CityWallSerializationTest extends SaveLoadBase<CityWall> {
    private DependentAnnotationConfigApplicationContext context;

    @BeforeEach
    private void initialize() {
        SpringApplicationBuilder builder = new SpringApplicationBuilder(SavegameTestApplication.class);
        context = (DependentAnnotationConfigApplicationContext) builder.contextClass(DependentAnnotationConfigApplicationContext.class).profiles("server").run();
   }
}

The SavegameTestApplication that is reverenced:受人尊敬的 SavegameTestApplication:

@SpringBootApplication
@Import({ServerTestConfiguration.class})
@PropertySource(value = {"application.properties", "server.properties"})
public class SavegameTestApplication {
}

The ServerTestConfiguration is a configuration that pulls together certain configuration and beans that are required: ServerTestConfiguration是一种配置,它将某些配置和所需的 bean 组合在一起:

@Configuration
@ActiveProfiles("server")
@Import(value = {ClientServerInterfaceServerConfiguration.class, ServerConfiguration.class, ImageConfiguration.class})
public class ServerTestConfiguration {
    @Bean
    public Jaxb2Marshaller jaxb2MarshallerImage() {
        Jaxb2Marshaller bean = new Jaxb2Marshaller();
        bean.setContextPath("ch.sahits.game.graphic.data.image");
        return bean;
    }
    @Bean
    public ITextSizing textSizing() {
        return new ITextSizing() {
            @Override
            public Dimension2D calculate(int size, Font font) {
                return null;
            }

            @Override
            public Dimension2D calculate(String text, Font font) {
                return null;
            }
        };
    }

    @Bean
    public IEventPropagator serverEventPropagator() {
        return message -> log.info("Propagate targeted event {}", message);
    }

    @Bean
    public TestableLoadAndSaveService testableLoadAndSaveService() {
        return new TestableLoadAndSaveService();
    }
}

Then the referenced ClientServerInterfaceServerConfiguration , where two beans are autowired:然后是引用的ClientServerInterfaceServerConfiguration ,其中两个 bean 是自动装配的:

@Configuration
@Profile("server")
@Import({ClientServerInterfaceCommonConfiguration.class})
@ClassCategory(EClassCategory.STARTUP)
public class ClientServerInterfaceServerConfiguration {
    @Autowired
    @Qualifier("serverThreadPool")
    private Executor serverThreadPool;
    @Autowired
    private SubscriptionLoggingExceptionHandler subscriptionExceptionHandler;

    @Bean
    public PausableAsyncEventBus clientServerEventBus() {
        return new PausableAsyncEventBus(serverThreadPool, subscriptionExceptionHandler);
    }
    @Bean
    public PausableSyncEventBus syncServerClientEventBus() {
        return new PausableSyncEventBus(subscriptionExceptionHandler);
    }


    @Bean
    public AsyncEventBus timerEventBus() {
        return new AsyncEventBus(serverThreadPool, subscriptionExceptionHandler);
    }
}

The two beans that are autowired are defined in the ClientServerInterfaceCommonConfiguration that is imported.自动装配的两个 bean 在导入的ClientServerInterfaceCommonConfiguration中定义。 When I start up the test with -Dlogging.level.org.springframework=DEBUG , I get this log output for the beans that are actually found (at least the start of the output, the large bulk is omitted as it does not have any relevance):当我使用-Dlogging.level.org.springframework=DEBUG启动测试时,我得到了实际找到的 bean 的日志输出(至少在输出的开始,省略了大块,因为它没有任何关联):

2019-12-11 17:07:52,487 [main] INFO   c.i.r.j.JUnitStarter : The following profiles are active: server
2019-12-11 17:07:52,487 [main] DEBUG  o.s.b.SpringApplication : Loading source class ch.sahits.game.savegame.SavegameTestApplication
2019-12-11 17:07:52,517 [main] DEBUG  o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'file:/home/andi/development/intellij/OpenPatrician/OpenPatricianTest/target/classes/application.properties' (classpath:/application.properties)
2019-12-11 17:07:52,583 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianTest/target/test-classes/ch/sahits/game/savegame/ServerTestConfiguration.class]
2019-12-11 17:07:52,608 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/ClientServerInterfaceServerConfiguration.class]
2019-12-11 17:07:52,611 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/event/BuyWares.class]
2019-12-11 17:07:52,612 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/event/PostponedDisplayDialogMessage.class]
2019-12-11 17:07:52,613 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/event/PostponedDisplayMessage.class]
2019-12-11 17:07:52,615 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/logging/EventBusAspect.class]
2019-12-11 17:07:52,617 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/PathInterpolatorMap.class]
2019-12-11 17:07:52,624 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/AIStrategyLoader.class]
2019-12-11 17:07:52,625 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/BuildingFactory.class]
2019-12-11 17:07:52,626 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/CityFactory.class]
2019-12-11 17:07:52,627 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/GameFactory.class]
2019-12-11 17:07:52,627 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/MapSegmentImageFactory.class]
2019-12-11 17:07:52,628 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/PeopleFactory.class]
2019-12-11 17:07:52,628 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/PlayerInteractionFactory.class]
2019-12-11 17:07:52,628 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/ShipFactory.class]
2019-12-11 17:07:52,629 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/factory/StateFactory.class]
2019-12-11 17:07:52,629 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/task/CelebrationTask.class]
2019-12-11 17:07:52,630 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/task/MarriageTask.class]
2019-12-11 17:07:52,630 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/task/ReschedulableSailorHireTask.class]
2019-12-11 17:07:52,630 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/model/task/ReschedulableWeaponBuyTask.class]
2019-12-11 17:07:52,631 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/BuildingProduction.class]
2019-12-11 17:07:52,631 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/CelebrationService.class]
2019-12-11 17:07:52,632 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/CityProductionAndConsumptionService.class]
2019-12-11 17:07:52,632 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/ClientServerFactory.class]
2019-12-11 17:07:52,632 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/ClientServerTaskFactory.class]
2019-12-11 17:07:52,633 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/ConvoyService.class]
2019-12-11 17:07:52,633 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/DateService.class]
2019-12-11 17:07:52,634 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/DialogTemplateFactory.class]
2019-12-11 17:07:52,634 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/DifficultyPropertyInitializer.class]
2019-12-11 17:07:52,635 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/FormattedDateSupplier.class]
2019-12-11 17:07:52,635 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/GuildService.class]
2019-12-11 17:07:52,636 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/LinearDeadlinePremiumCalculator.class]
2019-12-11 17:07:52,636 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/LoanerService.class]
2019-12-11 17:07:52,636 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/MapProxy.class]
2019-12-11 17:07:52,637 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/MapService.class]
2019-12-11 17:07:52,637 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/ModelStateAccessor.class]
2019-12-11 17:07:52,637 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/OutriggerService.class]
2019-12-11 17:07:52,638 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/PlayerProductionService.class]
2019-12-11 17:07:52,638 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/PointService.class]
2019-12-11 17:07:52,639 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/ShipService.class]
2019-12-11 17:07:52,639 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/StrategyHolderService.class]
2019-12-11 17:07:52,640 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/service/TradeService.class]
2019-12-11 17:07:52,661 [main] DEBUG  o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/ClientServerInterfaceServerConfiguration.class]

The peculiar thing that I cannot understand is: Why is ClientServerInterfaceServerConfiguration twice in the list, but ClientServerInterfaceCommonConfiguration is missing alltogether?我无法理解的奇特之处是:为什么ClientServerInterfaceServerConfiguration在列表中出现了两次,而ClientServerInterfaceCommonConfiguration却全部丢失了?

This of course ends with the application context failing to be built:这当然以无法构建应用程序上下文结束:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.concurrent.Executor' available: expected at least 1 bean which qualifies as autowire candidate.引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“java.util.concurrent.Executor”类型的合格bean:预计至少有1个符合自动装配候选资格的bean。 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value="serverThreadPool")}依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value="serverThreadPool")}

UPDATE: When running with trace logging there are some more interessting tidbits:更新:当使用跟踪日志运行时,有一些更有趣的花絮:

2019-12-12 12:58:53,469 [main] TRACE  o.s.c.a.ClassPathBeanDefinitionScanner : Scanning file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/ClientServerInterfaceCommonConfiguration.class]
2019-12-12 12:58:53,470 [main] TRACE  o.s.c.a.ClassPathBeanDefinitionScanner : Ignored because not matching any filter: file [/home/andi/development/intellij/OpenPatrician/OpenPatricianClientServerInterface/target/classes/ch/sahits/game/openpatrician/clientserverinterface/ClientServerInterfaceCommonConfiguration.class]

This is actually ok, as the configuration class is ignored on component scan, as it is imported.这实际上是可以的,因为在组件扫描时会忽略配置类,因为它是导入的。

2019-12-12 13:00:04,484 [main] TRACE  o.s.c.a.ConfigurationClassBeanDefinitionReader : Registered bean definition for imported class 'ch.sahits.game.openpatrician.clientserverinterface.ClientServerInterfaceCommonConfiguration'
2019-12-12 13:00:04,484 [main] TRACE  o.s.c.a.ConfigurationClassBeanDefinitionReader : Registering bean definition for @Bean method ch.sahits.game.openpatrician.clientserverinterface.ClientServerInterfaceCommonConfiguration.serverThreadPool()
2019-12-12 13:00:04,484 [main] TRACE  o.s.c.a.ConfigurationClassBeanDefinitionReader : Registering bean definition for @Bean method ch.sahits.game.openpatrician.clientserverinterface.ClientServerInterfaceCommonConfiguration.subscriptionExceptionHandler()

The configuration is actually handled and the beans are registered (at least with the definition reader).实际处理配置并注册 bean(至少使用定义阅读器)。 The actual exception happens here:实际的异常发生在这里:

2019-12-12 13:00:09,516 [main] TRACE  o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'serverConfiguration'
2019-12-12 13:00:09,516 [main] TRACE  o.s.b.f.a.InjectionMetadata : Registered injected element on class [ch.sahits.game.openpatrician.server.ServerConfiguration$$EnhancerBySpringCGLIB$$b77d1330]: AutowiredFieldElement for private java.util.concurrent.Executor ch.sahits.game.openpatrician.server.ServerConfiguration.serverThreadPool
2019-12-12 13:00:09,516 [main] TRACE  o.s.b.f.a.InjectionMetadata : Registered injected element on class [ch.sahits.game.openpatrician.server.ServerConfiguration$$EnhancerBySpringCGLIB$$b77d1330]: AutowiredFieldElement for private ch.sahits.game.openpatrician.clientserverinterface.event.SubscriptionLoggingExceptionHandler ch.sahits.game.openpatrician.server.ServerConfiguration.subscriptionExceptionHandler
2019-12-12 13:00:09,516 [main] TRACE  o.s.b.f.s.DefaultListableBeanFactory : Eagerly caching bean 'serverConfiguration' to allow for resolving potential circular references
2019-12-12 13:00:09,516 [main] TRACE  o.s.b.CachedIntrospectionResults : Getting BeanInfo for class [ch.sahits.game.openpatrician.server.ServerConfiguration$$EnhancerBySpringCGLIB$$b77d1330]
2019-12-12 13:00:09,517 [main] TRACE  o.s.b.CachedIntrospectionResults : Caching PropertyDescriptors for class [ch.sahits.game.openpatrician.server.ServerConfiguration$$EnhancerBySpringCGLIB$$b77d1330]
2019-12-12 13:00:09,517 [main] TRACE  o.s.b.CachedIntrospectionResults : Found bean property 'beanFactory' of type [org.springframework.beans.factory.BeanFactory]
2019-12-12 13:00:09,517 [main] TRACE  o.s.b.CachedIntrospectionResults : Found bean property 'class' of type [java.lang.Class]
2019-12-12 13:00:09,519 [main] TRACE  o.s.b.f.a.InjectionMetadata : Processing injected element of bean 'serverConfiguration': AutowiredFieldElement for private java.util.concurrent.Executor ch.sahits.game.openpatrician.server.ServerConfiguration.serverThreadPool
2019-12-12 13:00:09,520 [main] TRACE  o.s.b.TypeConverterDelegate : Converting String to [class java.lang.Class] using property editor [org.springframework.beans.propertyeditors.ClassEditor@538e74fc]
2019-12-12 13:00:09,520 [main] TRACE  o.s.b.TypeConverterDelegate : Converting String to [class java.lang.Class] using property editor [org.springframework.beans.propertyeditors.ClassEditor@6475e778]
2019-12-12 13:00:09,520 [main] TRACE  o.s.b.TypeConverterDelegate : Converting String to [class java.lang.Class] using property editor [org.springframework.beans.propertyeditors.ClassEditor@55b62db8]
2019-12-12 13:00:09,521 [main] WARN   o.s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serverConfiguration': Unsatisfied dependency expressed through field 'serverThreadPool'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.concurrent.Executor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value="serverThreadPool")}

So the exception does not happen when trying to inject the serverThreadPool into ClientServerInterfaceServerConfiguration which imports ClientServerInterfaceCommonConfiguration , but when trying to injecting it into ServerConfiguration which does not import ClientServerInterfaceCommonConfiguration .因此,当试图注入的异常发生serverThreadPoolClientServerInterfaceServerConfiguration其中进口ClientServerInterfaceCommonConfiguration ,而是试图将其注入时ServerConfiguration这不导入ClientServerInterfaceCommonConfiguration Adding it to the ServerConfiguration solves this problem, but the question remains: Why is there an issue with injecting a bean in ServerConfiguration that is defined in a different Configuration , when both configuration classes are imported in the same 'parent' configuration?将它添加到ServerConfiguration解决了这个问题,但问题仍然存在:当两个配置类都导入到相同的“父”配置中时,为什么在不同的Configuration定义的ServerConfiguration中注入 bean 会出现问题?

The 'java.util.concurrent.Executor' would indicate missing asynchronous execution and scheduling of tasks with the TaskExecutor and TaskScheduler interfaces. 'java.util.concurrent.Executor' 将指示缺少 TaskExecutor 和 TaskScheduler 接口的任务异步执行和调度。 Spring documentation provides annotation support. Spring 文档提供了注解支持。 Try adding: @EnableAsync & @EnableScheduling - > to your @Configuration classes.尝试添加:@EnableAsync & @EnableScheduling - > 到您的 @Configuration 类。

example:例子:

@Configuration
@EnableAsync
@EnableScheduling
public class AppConfig {
}

refer to Spring-framework for further details and examples.有关更多详细信息和示例,请参阅Spring-framework

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM