From 1b0a5e38af20772f07125508ade50cf6c4b10f2e Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 25 Sep 2023 11:26:33 +0200 Subject: [PATCH] GH-1069 Ensure 'spring.main.banner-mode' is honored by ServerlessWebApplication Resolves #1069 --- .../function/serverless/web/ServerlessWebApplication.java | 7 +++++++ .../function/serverless/web/RequestResponseTests.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ServerlessWebApplication.java b/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ServerlessWebApplication.java index 1c4bcd3ed..38f940ea6 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ServerlessWebApplication.java +++ b/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ServerlessWebApplication.java @@ -155,6 +155,13 @@ private SpringApplicationRunListeners getRunListeners(String[] args) { private Banner printBanner(ConfigurableEnvironment environment) { ResourceLoader resourceLoader = (this.getResourceLoader() != null) ? this.getResourceLoader() : new DefaultResourceLoader(null); + Banner.Mode bannerMode = environment.containsProperty("spring.main.banner-mode") + ? Banner.Mode.valueOf(environment.getProperty("spring.main.banner-mode").trim().toUpperCase()) + : Banner.Mode.CONSOLE; + + if (bannerMode == Banner.Mode.OFF) { + return null; + } SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(resourceLoader, new SpringAwsBanner()); return bannerPrinter.print(environment, this.getMainApplicationClass(), System.out); } diff --git a/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/serverless/web/RequestResponseTests.java b/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/serverless/web/RequestResponseTests.java index 9e0411eb1..dde802d17 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/serverless/web/RequestResponseTests.java +++ b/spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/serverless/web/RequestResponseTests.java @@ -46,6 +46,7 @@ public class RequestResponseTests { @BeforeEach public void before() { + System.setProperty("spring.main.banner-mode", "off"); this.mvc = ProxyMvc.INSTANCE(ProxyErrorController.class, PetStoreSpringAppConfig.class); } @@ -136,6 +137,7 @@ public void validatePostWithBody() throws Exception { @Test public void validatePostAsyncWithBody() throws Exception { +// System.setProperty("spring.main.banner-mode", "off"); ProxyHttpServletRequest request = new ProxyHttpServletRequest(null, "POST", "/petsAsync/"); String jsonPet = "{\n" + " \"id\":\"1234\",\n"