无法使用 springdoc-openapi-maven-plugin 生成 Swagger.json 文件

Unable to generate Swagger.json file using springdoc-openapi-maven-plugin

我正在尝试在 Maven 构建期间生成 Swagger.json 文件。

这是我在 pom.xml 中来自 docs 的插件。

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springdoc</groupId>
                <artifactId>springdoc-openapi-maven-plugin</artifactId>
                <version>0.2</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                <apiDocsUrl>http://localhost:8080/registrationprocessor/v1/registrationstatus</apiDocsUrl>
                <outputFileName>openapi.json</outputFileName>
                <outputDir>${project.build.directory}</outputDir>
            </configuration>
            </plugin>

我看过这个repo。它在单独的项目中 运行ning 很好,但是当我试图在我的项目中 运行 时。它给 java.net.ConnectException: Connection refused (Connection refused)

完整的错误信息

[INFO] --- springdoc-openapi-maven-plugin:0.2:generate (integration-test) @ registration-processor-registration-status-service ---
[ERROR] An error has occured
java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect (Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:399)
    at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:242)
    at java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:224)
    at java.net.Socket.connect (Socket.java:609)
    at java.net.Socket.connect (Socket.java:558)
    at sun.net.NetworkClient.doConnect (NetworkClient.java:182)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:474)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:569)
    at sun.net.www.http.HttpClient.<init> (HttpClient.java:242)
    at sun.net.www.http.HttpClient.New (HttpClient.java:341)
    at sun.net.www.http.HttpClient.New (HttpClient.java:362)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient (HttpURLConnection.java:1253)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0 (HttpURLConnection.java:1187)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect (HttpURLConnection.java:1081)
    at sun.net.www.protocol.http.HttpURLConnection.connect (HttpURLConnection.java:1015)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1592)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1520)
    at java.net.HttpURLConnection.getResponseCode (HttpURLConnection.java:527)
    at org.springdoc.maven.plugin.SpringDocMojo.execute (SpringDocMojo.java:43)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

我已经尝试了 this Whosebug question and this github issue 的所有答案,但不幸的是,没有一个对我有用。

我们将不胜感激。

您的应用程序似乎不在 运行 端口 8080 上。请检查您的 Spring 配置,也许您设置了不同的端口?

Openapi.json 文件是在将 application.properties 的某些配置从 test 文件夹移动到 src 文件夹中的 bootstrap.properties 后生成的。但是每次我必须关闭端口 9001 才能生成 json 文件。