-
Notifications
You must be signed in to change notification settings - Fork 437
MissingWebServerFactoryBeanException for Spring Boot WebFlux 3.0.0 + Spring Cloud Contract 4.0.0-RC3 + SpringBootTest.WebEnvironment.RANDOM_PORT #1854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is my setup <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>1854</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>1854</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2022.0.0-RC3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-web-test-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>4.0.0-RC3</version>
<extensions>true</extensions>
<configuration>
<testFramework>JUNIT5</testFramework>
<testMode>WEBTESTCLIENT</testMode>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project> This is my test code package com.example4;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ApplicationTests {
@Test
void contextLoads() {
}
} And this is the outcome of
I can't replicate this issue - can you provide a reproducer please? |
@marcingrzejszczak I have created the project here : https://github.com/davidmelia/spring-cloud-contract-issue-1854 The difference is you need both of these for it to fail:
|
The dependency <groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId> Which seems to break things when you have Webflux and Contract on the classpath. The servlet api is used only for rest-docs . So if you're NOT using restdocs and WANT to use Spring Cloud Contract WireMock with Webflux you should exclude that dependency <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-wiremock</artifactId>
<exclusions>
<exclusion>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency> I can update the docs to reflect that. Would that be sufficient of a change? Another option is to make that dependency optional and document that if you're using RestDocs you should add it manually? Actually RestDocs assumes that that dependency is there at runtime so maybe we should do the same 🤔 |
I think I like your approach of making servlet-api an opt-in dependency. |
without this change if you use Spring Cloud Contract WireMock with e.g. WebFlux your Spring Boot context can fail to start beacuse of it can't decide whether the application should be reactive or not. with this change we're making the dependency optional because it should come from the user, we shouldn't be providing it. Also RestDocs are assuming that that dependency is a runtime one fixes gh-1854
Originally raised in spring-projects/spring-boot#33456 by @davidmelia
Hi,
If you create a Spring Boot 3.0.0 WebFlux Starter project and add
then the XXXApplicationTests which have been auto created work fine unless you add webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT e.g.
The above results in a org.springframework.boot.web.context.MissingWebServerFactoryBeanException which is a change in behaviour to Spring Boot 2.7.x
There are a few ways around this:
Thanks
Stack Trace:
The text was updated successfully, but these errors were encountered: