开发者社区> 问答> 正文

Spring Boot应用程序将忽略导入的配置

为了能够测试应用程序的某些方面,我创建了此测试设置。由于我需要自定义实现ApplicationContext,因此无法使用经典SpringBootTest注释完成,而是使用以下initialisazion:

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();
   }
}

受到尊敬的SavegameTestApplication:

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

的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();
    }
}

然后是引用的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);
    }
}

自动连线的两个bean在ClientServerInterfaceCommonConfiguration导入的中定义。当我使用启动测试时-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]

我无法理解的奇特的事情是:为什么ClientServerInterfaceServerConfiguration在列表中两次出现,却一起ClientServerInterfaceCommonConfiguration缺失?

这当然以无法构建应用程序上下文而结束:

由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'java.util.concurrent.Executor'的合格Bean:期望至少有1个有资格作为自动装配候选的Bean。依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true),@ org.springframework.beans.factory.annotation.Qualifier(value =“ serverThreadPool”)}

展开
收起
垚tutu 2019-12-12 09:57:47 1088 0
1 条回答
写回答
取消 提交回答
  • #include

    “ java.util.concurrent.Executor”将指示缺少带有TaskExecutor和TaskScheduler接口的异步执行和任务调度。Spring文档提供注释支持。尝试将@EnableAsync和@EnableScheduling->添加到您的@Configuration类。

    例:

    @Configuration
    @EnableAsync
    @EnableScheduling
    
    

    public class AppConfig { }

    2019-12-12 09:58:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载