Closed paul-ovchinnikov closed 4 years ago
You are missing this in your project, is Kotlin code but I guess you will understand the idea
@Configuration
class SecurityConfig() : WebSecurityConfigurerAdapter() {
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http
.csrf().disable()
.antMatcher("/**")
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.authorizeRequests()
.antMatchers("/v3/api-docs").permitAll()
.anyRequest().denyAll()
.and()
.httpBasic()
}
}
You are missing this in your project, is Kotlin code but I guess you will understand the idea
@Configuration class SecurityConfig() : WebSecurityConfigurerAdapter() { @Throws(Exception::class) override fun configure(http: HttpSecurity) { http .csrf().disable() .antMatcher("/**") .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.NEVER) .and() .authorizeRequests() .antMatchers("/v3/api-docs").permitAll() .anyRequest().denyAll() .and() .httpBasic() } }
could you elaborate a little, I cant translate it to my Java project
So, your problem is that you are not allowing access to the route where the swagger is exposed.
You need to create a configuration class and extend from WebSecurityConfigurerAdapter
and override the method configure(HttpSecurity http){....}
and allow the access to "/v3/api-docs"
path
If we run the spring context from a war deployment(No main class), How to solve java.net.ConnectException: Connection refused (Connection refused)?
The solution will be the same. You just need to find out how to expose the route "/v3/api-docs"
for a war
deployment, and I will assume is quite similar
Hi @RandyHBH
I've already to add route "/v3/api-docs"
both of WebSecurityConfigurerAdapter class and yaml file. but it still has Connection Refuse. This is my pom.
org.springframework.boot spring-boot-maven-plugin pre-integration-test start post-integration-test stop true -Dspring.application.admin.enabled=true org.springdoc springdoc-openapi-maven-plugin 1.3 integration-test generate ${project.build.directory}/springdoc
I have the exact same problem. Adding permission to the security configuration didn't solve the problem.
Btw, why is this issue closed?
@micobarac Could you share your project or a newly created one that reproduce the issue so I can take a look and see if I can help you?
I have almost the same configuration as @RandyHBH .
When I run
mvn -Pprod,war clean verify -DskipTests=true
I get:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.7.RELEASE:start (pre-integration-test) on project openprovider-cdb: Could not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Connection refused to host: 127.0.0.1; nested exception is:
[ERROR] java.net.ConnectException: Connection refused (Connection refused)
[ERROR] -> [Help 1]
[ERROR]
The huge question is: Must the application be app and running on port 8080 prior to running the command above?
Here is the significant part of pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<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>
<configuration>
<mainClass>${start-class}</mainClass>
<fork>true</fork>
<jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>
<!--
Enable the line below to have remote debugging of your application on port 5005
<jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
-->
</configuration>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
<outputFileName>openapi.json</outputFileName>
<outputDir>${project.basedir}/target/docs/asciidoc</outputDir>
</configuration>
</plugin>
I merged the existing spring-boot-maven-plugin settings with the one provided in your docs.
I made it work by removing:
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
and running the app on 8080, priror to running maven mvn -Pprod,war clean verify -DskipTests=true
command.
Had the same problem - the issue was in the custom path, which was setup in application.yml.
The huge question is: Must the application be app and running on port 8080 prior to running the command above?
This plugin only works if the app server is running before it can make the output file. In spring boot, we run tests before even building the artifact. How can I just generate the file without having to run the app server?
So I just read through your source code and you're scraping the URL to parse the json and then saving it to a file. This will not work for my automation needs where the file needs to be created at build, not deploy. The phase of Integration test is misleading.
URL urlForGetRequest = new URL(apiDocsUrl);
No way for that
Output log for
mvn clean verify -Dspring.application.admin.enabled=true
belowApplication was started
springdoc-openapi-maven-plugin:0.3:generate
pom.xml