Merge branch '2.7.x'

Closes gh-29376
This commit is contained in:
Phillip Webb
2022-01-12 15:32:51 -08:00
7 changed files with 93 additions and 26 deletions

View File

@@ -6,7 +6,8 @@ plugins {
description = "Spring Boot profile smoke test"
dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-webflux"))
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -21,7 +21,9 @@ import smoketest.profile.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.ConfigurableEnvironment;
@SpringBootApplication
public class SampleProfileApplication implements CommandLineRunner {
@@ -38,8 +40,16 @@ public class SampleProfileApplication implements CommandLineRunner {
System.out.println(this.helloWorldService.getMessage());
}
public static void main(String[] args) {
SpringApplication.run(SampleProfileApplication.class, args);
public static void main(String... args) {
SpringApplication application = new SpringApplication(SampleProfileApplication.class) {
@Override
protected void bindToSpringApplication(ConfigurableEnvironment environment) {
}
};
application.setWebApplicationType(WebApplicationType.NONE);
application.run(args);
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2012-2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoketest.profile;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.assertj.core.api.Assertions.assertThat;
// gh-29169
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class AttributeInjectionTests {
@Autowired(required = false)
private org.springframework.boot.web.servlet.error.ErrorAttributes errorAttributesServlet;
@Autowired(required = false)
private org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributesReactive;
@Test
void contextLoads() {
assertThat(this.errorAttributesServlet).isNull();
assertThat(this.errorAttributesReactive).isNotNull();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -48,14 +48,14 @@ class SampleProfileApplicationTests {
@Test
void testDefaultProfile(CapturedOutput output) {
SampleProfileApplication.main(new String[0]);
SampleProfileApplication.main();
assertThat(output).contains("Hello Phil");
}
@Test
void testGoodbyeProfile(CapturedOutput output) {
System.setProperty("spring.profiles.active", "goodbye");
SampleProfileApplication.main(new String[0]);
SampleProfileApplication.main();
assertThat(output).contains("Goodbye Everyone");
}
@@ -68,13 +68,13 @@ class SampleProfileApplicationTests {
* "name" property.
*/
System.setProperty("spring.profiles.active", "generic");
SampleProfileApplication.main(new String[0]);
SampleProfileApplication.main();
assertThat(output).contains("Bonjour Phil");
}
@Test
void testGoodbyeProfileFromCommandline(CapturedOutput output) {
SampleProfileApplication.main(new String[] { "--spring.profiles.active=goodbye" });
SampleProfileApplication.main("--spring.profiles.active=goodbye");
assertThat(output).contains("Goodbye Everyone");
}

View File

@@ -0,0 +1 @@
spring.main.web-application-type=reactive