restdocs-api-spec icon indicating copy to clipboard operation
restdocs-api-spec copied to clipboard

Connection refused with Spring Boot Starter Webflux

Open mikrethor opened this issue 1 year ago • 2 comments

For my tests I use com.epages:restdocs-api-spec-restassured and my application is developed with spring-boot-starter-webflux unfortunately restdocs-api-spec contains spring-boot-starter-web and it makes the tests fails with a connection refused so my test is not working.

For my use case I use the maven plugin

<groupId>io.github.berkleytechnologyservices</groupId>
<artifactId>restdocs-spec-maven-plugin</artifactId>

And the latest version (0.19.4).

So to make it work I exclude spring-boot-starter-web from restdocs-api-spec with the following code :

<dependency>
            <groupId>com.epages</groupId>
            <artifactId>restdocs-api-spec</artifactId>
            <version>${restdocs-api-spec.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

The code doesn't need to include the spring-boot-starter-web it can just use spring framework dependencies spring-web and spring-context.

mikrethor avatar Oct 19 '24 21:10 mikrethor

See https://github.com/mikrethor/demo-epages-restdocs-api-spec-restassured to reproduce

mikrethor avatar Oct 19 '24 21:10 mikrethor

I suffered the same problem with this; wrong webflux dependency on the spring-boot-starter-web. After further analysis, spring-boot-starter-web has implicit dependency on the tomcat server and does not work with built-in webflux's netty server.

I solved it by excluding webflux dependency from restdocs-api-spec library but author's solution seems to be more appropriate.

earthfall avatar Dec 23 '24 13:12 earthfall