1

I got latest Spring Boot app and springdoc.swagger-ui on board.

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.2.32</version>
</dependency>

My application.properties contains springdoc.swagger-ui.path=/swagger-ui-openapi.html

When I run application via Intellij IDEA http://localhost:8080/swagger-ui-openapi.html brings me to http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config and Swagger UI page loads successfully.

But if I start the app via command line: "java -jar my-app.jar", I got 404 in browser and Error in logs 'Circular view path [error]' when trying to reach http://localhost:8080/swagger-ui-openapi.html and it redirrects me to http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config

javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

However http://localhost:8080/v3/api-docs is reachable and schema is available at this address.

How can I fix this?

splekhanov
  • 116
  • 1
  • 2
  • 9
  • you need `swagger-annotations` dependency?. Run your app after removing it. Might be causing dependency conflict – Suraj Jun 17 '20 at 05:13
  • @Suraj Hello! Tried with dependency and without it - same result. Besides, I suppose if it was a dependency conflict the issue would reproduce when running from IDEA either, but it doesn't. – splekhanov Jun 17 '20 at 06:33
  • I tried a sample application using those two dependencies and it worked. Looks like some other issue – Suraj Jun 17 '20 at 15:27

3 Answers3

3

What worked in my case when your application is running behind a proxy, a load-balancer or in the cloud.

In your Spring Boot application make sure your application handles this header: X-Forwarded-For.

There are two ways to achieve this:

In your properties file add:

server.use-forward-headers=true

If this is not enough, Spring Framework provides a ForwardedHeaderFilter. You can register it as a Servlet Filter in your application by setting server.forward-headers-strategy is set to FRAMEWORK.

Since Spring Boot 2.2, this is the new property to handle reverse proxy headers:

In your properties file add

server.forward-headers-strategy=framework

And you can add the following bean to your application:

@Bean
ForwardedHeaderFilter forwardedHeaderFilter() {
   return new ForwardedHeaderFilter();
}

If you already have static content on your root, and you don’t want it to be overridden by springdoc-openapi-ui configuration, you can just define a custom configuration of the swagger-ui, in order not to override the configuration of your files from in your context-root:

For example use in your properties file:

springdoc.swagger-ui.path= /swagger-ui/api-docs.html

ref: https://springdoc.org/

1

For this problem, my conclusion is: (1) Starting it in IDEA is fine (2) Repackaging the jar with spring-boot-maven-plugin and starting it with 'java -jar' is fine as well. (3) if I tried to starting with such as 'java -classpath ".:.conf" DemoApplication', it does not work.

So, for packaging, i use the spring-boot-maven-plugin.

Dongsong
  • 11
  • 1
0

You don't need swagger-annotations v1.6.1 dependency for springdoc-openapi;

By default, with springdoc you need no additonal settings of any ViewResolver.

You can have a look at some sample code:

brianbro
  • 4,141
  • 2
  • 24
  • 37
  • 1
    I've deleted swagger-annotations and left only springdoc-openapi-ui dependency. And again, I do not have any additonal settings of any ViewResolver. When I run the app from IDEA and go http://localhost:8080/swagger-ui.html - everything works fine. But if I package my app into jar and run it "java -jar my-app.jar" - I got 404 at http://localhost:8080/swagger-ui.html The same thing happens if I use custom path like springdoc.swagger-ui.path=/mypath/swagger-ui.html – splekhanov Jun 18 '20 at 09:50
  • 1
    By the way... if I start application as: mvn spring-boot:start - everything works great. The problem is only with direct java -jar launching – splekhanov Jun 18 '20 at 10:09
  • 1
    It seems like it's a bug. I created new project with only starter and springdoc dependency and the problem still stands. I'll try to create an issue at springdoc git, let's see what they answer. – splekhanov Jun 18 '20 at 10:40
  • It's not a bug. Something different. I tried to build same repo and started jar - on another PC everything worked fine. I updated java, deleted .m2 and download dependencies again, but nothing helped yet... – splekhanov Jun 18 '20 at 13:32
  • Hi, I am facing the same problem as you with 404. mvn spring-boot:start works fine but when I deployed built war to wildfly I got 404. Did you find any solution? – Dušan Salay Oct 27 '20 at 19:34
  • 1
    @DušanSalay see this section for wildfly: https://springdoc.org/#integration-with-wildfly – brianbro May 23 '21 at 17:00