diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle index 51210a79385..cba62a99b21 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle @@ -11,7 +11,6 @@ configurations { dependencies { testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - testImplementation(project(":spring-boot-project:spring-boot-actuator-autoconfigure")) testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) testImplementation("com.samskivert:jmustache") testImplementation("jakarta.servlet:jakarta.servlet-api") @@ -26,7 +25,6 @@ dependencies { testRepository(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter", configuration: "mavenRepository")) - testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-json", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-parent", configuration: "mavenRepository")) diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java index c0d5650311e..7b11408097f 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -16,27 +16,44 @@ package com.autoconfig; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.springframework.boot.autoconfigure.condition.ConditionalOnWarDeployment; +import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; -@ConditionalOnWarDeployment @Configuration public class ExampleAutoConfiguration { @Bean - public TestEndpoint testEndpoint() { - return new TestEndpoint(); + @ConditionalOnWarDeployment + public ServletRegistrationBean onWarTestServlet() { + ServletRegistrationBean registration = new ServletRegistrationBean<>(new TestServlet()); + registration.addUrlMappings("/conditionalOnWar"); + return registration; } - @Endpoint(id = "war") - static class TestEndpoint { + @Bean + public ServletRegistrationBean testServlet() { + ServletRegistrationBean registration = new ServletRegistrationBean<>(new TestServlet()); + registration.addUrlMappings("/always"); + return registration; + } - @ReadOperation - String hello() { - return "{\"hello\":\"world\"}"; + static class TestServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType(MediaType.APPLICATION_JSON_VALUE); + resp.getWriter().println("{\"hello\":\"world\"}"); + resp.flushBuffer(); } } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java index bc40dc94de1..7ced703b8d6 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java @@ -56,8 +56,16 @@ public class ResourceHandlingApplication { } public static void main(String[] args) { - new SpringApplicationBuilder(ResourceHandlingApplication.class).properties("server.port:0") - .listeners(new WebServerPortFileWriter(args[0])).run(args); + try { + Class.forName("org.springframework.web.servlet.DispatcherServlet"); + System.err.println("Spring MVC must not be present, otherwise its static resource handling " + + "will be used rather than the embedded containers'"); + System.exit(1); + } + catch (Throwable ex) { + new SpringApplicationBuilder(ResourceHandlingApplication.class).properties("server.port:0") + .listeners(new WebServerPortFileWriter(args[0])).run(args); + } } private static final class GetResourcePathsServlet extends HttpServlet { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java index 38e711ad20f..4683c0cb444 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java @@ -91,6 +91,7 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback { List arguments = new ArrayList<>(); arguments.add(System.getProperty("java.home") + "/bin/java"); arguments.addAll(getArguments(archive, serverPortFile)); + arguments.add("--server.servlet.register-default-servlet=true"); ProcessBuilder processBuilder = new ProcessBuilder(StringUtils.toStringArray(arguments)); if (workingDirectory != null) { processBuilder.directory(workingDirectory); diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java index 9b4f0fcbd94..b8365b1ed69 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -161,8 +161,6 @@ class ApplicationBuilder { metaInf.mkdirs(); FileCopyUtils.copy(new File("src/test/resources/META-INF/spring.factories"), new File(metaInf, "spring.factories")); - FileCopyUtils.copy(new File("src/test/resources/application.yml"), - new File(srcMainResources, "application.yml")); } private void packageApplication(File appDirectory, File settingsXml) throws MavenInvocationException { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java index 610a228495a..04fe90fd5d7 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -81,7 +81,7 @@ class EmbeddedServletContainerJarPackagingIntegrationTests { @TestTemplate void conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer(RestTemplate rest) { - ResponseEntity entity = rest.getForEntity("/actuator/war", String.class); + ResponseEntity entity = rest.getForEntity("/war", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java index 767999197d1..5ec90ffd945 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -104,8 +104,9 @@ class EmbeddedServletContainerWarPackagingIntegrationTests { @TestTemplate void conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer(RestTemplate rest) { - ResponseEntity entity = rest.getForEntity("/actuator/war", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(rest.getForEntity("/always", String.class).getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(rest.getForEntity("/conditionalOnWar", String.class).getStatusCode()) + .isEqualTo(HttpStatus.NOT_FOUND); } private List readLines(String input) { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/application.yml b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/application.yml deleted file mode 100644 index 8099f86ce86..00000000000 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/application.yml +++ /dev/null @@ -1 +0,0 @@ -management.endpoints.web.exposure.include: '*' diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml index 546c9cc0653..3b855f17333 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml @@ -18,11 +18,7 @@ org.springframework.boot - spring-boot-starter-json - - - org.springframework.boot - spring-boot-starter-actuator + spring-boot-starter org.springframework.boot @@ -30,7 +26,7 @@ org.springframework - spring-webmvc + spring-web javax.servlet