From 4977e48ec5c769c8d39e4bf520e5174e266f34bc Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 11 May 2015 15:43:44 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20rely=20on=20deduction=20of=20ma?= =?UTF-8?q?in=20application=20class=20when=20running=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when SpringApplicationContextLoader created a SpringApplication and used it to load the test’s application context, it relied upon SpringApplication correctly deducing the application’s main class. This would result in the wrong class being deduced as the application’s main method is not called so the test runner’s main method would be found instead. This commit updates SpringApplicationContextLoader to explicitly set SpringApplication’s main class to be the current test’s class. While not strictly the application’s main class, it is the next best thing available in this situation and prevents misleading log messages and application versions from being logged. Fixes gh-2930 --- .../boot/test/SpringApplicationContextLoader.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index ce60e0a1f4f..ff49efee56f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -68,6 +68,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext; * * @author Dave Syer * @author Phillip Webb + * @author Andy Wilkinson * @see IntegrationTest * @see WebIntegrationTest * @see TestRestTemplate @@ -81,6 +82,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { throws Exception { assertValidAnnotations(config.getTestClass()); SpringApplication application = getSpringApplication(); + application.setMainApplicationClass(config.getTestClass()); application.setSources(getSources(config)); ConfigurableEnvironment environment = new StandardEnvironment(); if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {