From 04307aa7e02c8c10830cc59dce29a101897b0905 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 17 Oct 2023 11:48:41 +0100 Subject: [PATCH] Polish "Support @Order on [CommandLine|Application]Runner @Bean definitions" See gh-37905 --- .../org/springframework/boot/ApplicationRunner.java | 2 +- .../org/springframework/boot/CommandLineRunner.java | 2 +- .../springframework/boot/SpringApplicationTests.java | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ApplicationRunner.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ApplicationRunner.java index 08175746086b..c07e6091ba72 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ApplicationRunner.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ApplicationRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/CommandLineRunner.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/CommandLineRunner.java index 855dd6d29a26..87fda64a689d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/CommandLineRunner.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/CommandLineRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index d31419c0c398..133db585581c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -670,11 +670,11 @@ void runCommandLineRunnersAndApplicationRunners() { } @Test - void runFunctionalCommandLineRunnersAndApplicationRunners() { - SpringApplication application = new SpringApplication(FunctionalRunnerConfig.class); + void runCommandLineRunnersAndApplicationRunnersUsingOrderOnBeanDefinitions() { + SpringApplication application = new SpringApplication(BeanDefinitionOrderRunnerConfig.class); application.setWebApplicationType(WebApplicationType.NONE); this.context = application.run("arg"); - FunctionalRunnerConfig config = this.context.getBean(FunctionalRunnerConfig.class); + BeanDefinitionOrderRunnerConfig config = this.context.getBean(BeanDefinitionOrderRunnerConfig.class); assertThat(config.runners).containsExactly("runnerA", "runnerB", "runnerC"); } @@ -1585,12 +1585,12 @@ TestCommandLineRunner runnerA() { } @Configuration(proxyBeanMethods = false) - static class FunctionalRunnerConfig { + static class BeanDefinitionOrderRunnerConfig { - List runners = new ArrayList<>(); + private final List runners = new ArrayList<>(); @Bean - @Order // default is LOWEST_PRECEDENCE + @Order CommandLineRunner runnerC() { return (args) -> this.runners.add("runnerC"); }