Provide a condition for detecting war deployments
Closes gh-19421
This commit is contained in:
@@ -10,6 +10,7 @@ dependencies {
|
||||
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) {
|
||||
exclude group: "org.hibernate.validator"
|
||||
}
|
||||
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
|
||||
|
||||
intTestImplementation(enforcedPlatform(project(path: ":spring-boot-project:spring-boot-parent")))
|
||||
intTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
||||
@@ -20,8 +21,6 @@ dependencies {
|
||||
intTestImplementation("org.springframework:spring-web")
|
||||
|
||||
providedRuntime(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-tomcat"))
|
||||
|
||||
runtimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
|
||||
}
|
||||
|
||||
intTest {
|
||||
|
||||
@@ -66,6 +66,16 @@ class DeploymentIntegrationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("deployedApplications")
|
||||
void conditionalOnWarShouldBeTrue(DeployedApplication application) throws Exception {
|
||||
application.test((rest) -> {
|
||||
ResponseEntity<String> response = rest.getForEntity("/actuator/war", String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.getBody()).isEqualTo("{\"hello\":\"world\"}");
|
||||
});
|
||||
}
|
||||
|
||||
static List<DeployedApplication> deployedApplications() {
|
||||
return Arrays.asList(new DeployedApplication("open-liberty:19.0.0.9-webProfile8", "/config/dropins", 9080),
|
||||
new DeployedApplication("tomcat:9.0.29-jdk8-openjdk", "/usr/local/tomcat/webapps", 8080),
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.app;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
package sample.app;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2012-2020 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 sample.autoconfig;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWarDeployment;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@ConditionalOnWarDeployment
|
||||
@Configuration
|
||||
public class ExampleAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public TestEndpoint testEndpoint() {
|
||||
return new TestEndpoint();
|
||||
}
|
||||
|
||||
@Endpoint(id = "war")
|
||||
static class TestEndpoint {
|
||||
|
||||
@ReadOperation
|
||||
String hello() {
|
||||
return "{\"hello\":\"world\"}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
sample.autoconfig.ExampleAutoConfiguration
|
||||
@@ -0,0 +1 @@
|
||||
management.endpoints.web.exposure.include: '*'
|
||||
Reference in New Issue
Block a user