Springdoc: got 404 when open swagger-ui.html - spring-boot

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?

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/

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.

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:
https://github.com/springdoc/springdoc-openapi-demos

Related

spring-boot 2.5.5 property "spring.config.import" not defined?

after upgrade spring-boot:2.3.11.RELEASE to spring-boot:2.5.5 and spring-cloud:Hoxton.SR11 to spring-cloud:2020.0.4, spring-boot:run is failing with:
***************************
APPLICATION FAILED TO START
***************************
Description:
No spring.config.import property has been defined
Action:
Add a spring.config.import=configserver: property to your configuration.
If configuration is not required add spring.config.import=optional:configserver: instead.
To disable this check, set spring.cloud.config.enabled=false or
spring.cloud.config.import-check.enabled=false.
Advices are pretty clear so I added
spring.cloud.config.enabled=false
spring.cloud.config.import-check.enabled=false
spring.config.import=optional:configserver:
to both application.properties and bootstrap.properties files
In application.properties I had to comment out line spring.config.import=optional:configserver: otherwise it failed with java.lang.IllegalStateException: Unable to load config data from 'optional:configserver:' ......... Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader
As I didn't need to comment it out in bootstrap.properties, values are ignored completely there probably
However application itself failed the same way as without any new properties added.
Any ideas what is the problem? What is correct format for spring.config.import=... ?
EDIT:
after adding dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
it doesn't ignore properties in bootstrap.properties anymore so I had to comment out "spring.config.import=optional:configserver:" there as well. However application still failing with "No spring.config.import property has been defined"
In Spring Cloud 2020 you dont need bootstrap.properties anymore, importing spring-cloud-starter-bootstrap enable only a legacy way to use it.
Just remove it...
You need to add
spring.config.import=optional:configserver:http://your.config.server.com
into your application.properties. Howerver I not sure what you try to achieve, because of your
spring.cloud.config.enabled=false
More Info

Spring Cloud Config: client doesn't attempt to connect to the config server

I'm trying to create a simple Spring Cloud Config server/client setup and am loosely following the documentation:
https://cloud.spring.io/spring-cloud-config/reference/html/
I've so far implemented a server that seems to work correctly, i.e. return the correct property values when I call the corresponding endpoint:
GET http://localhost:8888/config-client/development
{
"name": "config-client",
"profiles": [
"development"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "classpath:/config/config-client-development.properties",
"source": {
"user.role": "Developer"
}
}
]
}
I'm, however, not having any luck with getting the client to connect to the server. I have done the following:
Added the spring-cloud-starter-config dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Added a bootstrap.properties file:
spring.application.name=config-client
spring.profiles.active=development
spring.cloud.config.uri=http://localhost:8888
But I'm still getting a
java.lang.IllegalArgumentException: Could not resolve placeholder 'user.role' in value "${user.role}"
when trying to run the client application.
There is nothing in the application log that even looks like the client is attempting to communicate with the configuration server.
Link to a minimal GitHub repository that reproduces the issue:
https://github.com/Bragolgirith/spring-cloud-minimal
Steps to reproduce:
Build and run the config-service application
Build and run the config-client application
Any idea what I'm doing wrong?
OK, mistery solved.
It seems a new Spring Cloud version was released a week ago (https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available) that has a new way to activate the bootstrap process - now it doesn't happen by default, but requires adding an additional dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Although this new version is now the default you get when using the
Spring Initializr, the documentation is still not updated to reflect the changes - they are only briefly mentioned in the release notes.
As an alternative to using the abovementioned spring-cloud-starter-bootstrap dependency and a bootstrap.properties file, it seems the following is now also possible (and even preferred):
application.properties
spring.application.name=config-client
spring.profiles.active=development
spring.config.import=configserver:http://localhost:8888

RESTEASY003210: Could not find resource for full path - Quarkus

I'm trying to configure Swagger in Quarkus.
My version of Quarkus: 1.9.2.Final
My dependency:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
And my properties resources:
quarkus.swagger-ui.path=/swagger-ui
quarkus.swagger-ui.always-include=true
When I launch my application with: mvn compile quarkus:dev and go to this url:
http://localhost:8080/swagger-ui_not_found/
A red page with the additional endpoints is shown (ok, this is what I want)
However, if I make a package with maven (mvn package) and then, launch the jar, the same url returns:
RESTEASY003210: Could not find resource for full path
This is the trace:
2020-11-10 07:58:08,244 DEBUG [org.jbo.res.res.i18n] (executor-thread-1) RESTEASY002315: PathInfo: /favicon.ico
2020-11-10 07:58:08,246 DEBUG [org.jbo.res.res.i18n] (executor-thread-1) RESTEASY002305: Failed executing GET /favicon.ico: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/favicon.ico
at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:70)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:47)
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:481)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:332)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:253)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
I've read in Quarkus guides that if you set:
quarkus.swagger-ui.always-include=true
You make it available in production too, but in my case It doesn't work.
Any ideas?
Thanks.
Are you looking for the swagger-ui page, or the 404 page with the links on ?
As far as I know, the 404 with the links is only available in DEV mode.
By adding quarkus.swagger-ui.always-include=true to application.properties, you will get SwaggerUI in the prod-mode jar as well (accessible at http://localhost:8080/swagger-ui/)
See the documentation for more details.
Also note that this property is a build-time property, therefore changing it at runtime has no effect.

com.bedatadriven.jackson.datatype.jts.JtsModule not working with springboot 2.2.4

I am trying to serialize/deserialize org.locationtech.jts.geom.Geometry(version 1.16.0) using com.bedatadriven.jackson.datatype.jts.JtsModule. It comes packaged with:
<dependency>
<groupId>com.graphhopper.external</groupId>
<artifactId>jackson-datatype-jts</artifactId>
<version>1.0-2.7</version>
</dependency>
I have registered it using spring configuration mechanism:
#Bean
public JtsModule jtsModule()
{
return new JtsModule();
}
But somehow com.bedatadriven.jackson.datatype.jts.serialization.GeometryDeserializer is not invoked.
Is there something else needed to be done?
GeometryDeserializer / GeometrySerializer worked for com.vividsolutions.jts.geom.Geometry
An issue is open about it here
You can create your custom serializer and deserializer for org.locationtech.jts.geom.Geometry using same code available.
Example for point
There is a PR for Upgrade to Locationtech jts but not merged yet

Error with webservices springboot

I have got an error with creating webservice from wsdl.
I have already configred a maven plugin
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
for creation of java classes.
In my wsdl I have got reference to swaref.xsd
<xs:import namespace="http://ws-i.org/profiles/basic/1.1/xsd" schemaLocation="swaref.xsd"/>
When I launch springBoot app, I have got the following error:
Have you got any idea what's wrong? Maybe with apache cxf ?
Check if swaref.xsd exists along with the wsdl-file in the same location
Check if swaref.xsd contains the same namespace http://ws-i.org/profiles/basic/1.1/xsd, as referenced in wsdl-file
Check if swaref.xsd is a valid xml, then is a valid schema file.

Resources