0

I am trying to generate the Swagger.json file during maven build time.

This is my plugin in pom.xml from 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>

I have seen this repo. It's running fine in the separate project but when I am trying to run in my project. It's giving java.net.ConnectException: Connection refused (Connection refused)

Full error message

[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)

I have tried all answers of this stackoverflow question and this github issue but unfortunately non of them working for me.

Any help will be appreciated.

kameshsr
  • 327
  • 3
  • 13

2 Answers2

1

It looks like your application isn't running on port 8080. Check your Spring config, maybe you have set a different port?

jhyot
  • 3,733
  • 1
  • 27
  • 44
  • 1
    I have checked port number it's 8080 only. I want to generate swagger.json during maven build. – kameshsr May 01 '21 at 09:35
  • 1
    Ok. I would say there's something wrong with the apiDocsUrl. This should be the springdoc API endpoint, not your own endpoint. I would delete the apiDocsUrl element in your config. Usually it's not needed because the default value will work correctly. If the default doesn't work, then you have configured springdoc somewhere with a different endpoint and you need to show that configuration. – jhyot May 01 '21 at 09:47
  • 1
    Also check the official readme of the plugin: https://github.com/springdoc/springdoc-openapi-maven-plugin I see these differences to your pom: The version is currently already 1.1. And the jvmArguments element is missing from your config. – jhyot May 01 '21 at 09:52
  • Yes i have tried same plugin as documentation says but that also not working. In this repo https://github.com/mosip/registration/tree/master/registration-processor/init/registration-processor-registration-status-service i have put plugin in pom but i didn't pushed because its not working. – kameshsr May 01 '21 at 11:04
  • In your repo you have set the port to 8083, but above you told me that it is 8080. Which is it? See https://github.com/mosip/registration/blob/master/registration-processor/init/registration-processor-registration-status-service/src/main/resources/bootstrap.properties#L7 – jhyot May 01 '21 at 11:08
  • Sorry i tried with different port like 8083 8080 even 9001 but same error. – kameshsr May 01 '21 at 11:09
-3

Openapi.json file is generated after moving some configuration of application.properties from test folder to bootstrap.properties in src folder. But every time i have to kill port 9001 for generating json file.

kameshsr
  • 327
  • 3
  • 13