-
-
Notifications
You must be signed in to change notification settings - Fork 574
Description
Describe the bug
Spring application does not compile when both the springdoc-openapi-starter-webmvc-ui and spring-boot-data-rest dependencies are in a pom. This is also a transitive dependency of spring-boot-starter-data-rest. (The starter is a transitive dependency of another dependency my application requires.)
When both are present, Spring begins trying to load relevant configuration classes, which leads to the failure. This seems to be triggered by the inclusion of the openapi dependency when the spring-boot-data-rest/spring-boot-starter-data-rest dependency is present. The application will compile again when the openapi dependency is removed from the pom.
The Spring class responsible (I think) is org.springframework.boot.data.rest.autoconfigure.DataRestAutoConfiguration. It's a conditionally instantiated bean. From the javadoc:
Auto-configuration for Spring Data REST.
Activates when the application is a web application and no RepositoryRestMvcConfiguration is found.
Once in effect, the auto-configuration allows to configure any property of RepositoryRestConfiguration using the spring.data.rest prefix.
Since: 4.0.0
Temporary solution
I exclude spring-boot-data-rest from the spring-boot-starter-data-rest dependency (see sample code below)
To Reproduce
- What version of spring-boot you are using? 4.0.1
- What version of Java are you using? 21
- What modules and versions of springdoc-openapi are you using? org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.1
- What is the actual and the expected result using OpenAPI Description (yml or json)? n/a
- Provide with a sample code (HelloController) or Test that reproduces the problem: see below
Expected behavior
I expect my application to compile and run, and to provide a Swagger UI page at {root}/swagger-ui/index.html
Sample code:
pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>swagger-test</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>Swagger Test</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.0.1</version>
<relativePath/>
</parent>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<!-- UNCOMMENT TO ENABLE SWAGGER -->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-data-rest</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
</dependency>
</dependencies>
</project>
SwaggertestApplication.java
package org.example.swaggertest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SwaggertestApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggertestApplication.class, args);
}
}
TestController.java
package org.example.swaggertest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("test")
public String test() {
return "success";
}
}