I am using springdoc-open api for swagger integration in my springboot project.
I have added below property in application.yml
spring:
mvc:
pathmatch:
matching-strategy: ant_path_mathcher
and added below dependency in build.gralde file
implementation "org.springdoc:springdoc-openapi-ui:1.6.9"
I am able to access /v3/api-docs , but /swagger-ui/index.html and /swagger-ui.html giving 404 Whitelabel Error Page
After googling so many thins, I found a solution to this issue. I had to add an additional configuration class that is OpenApiConfig.java to make it work.
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = {"org.springdoc"})
#Import({org.springdoc.core.SpringDocConfiguration.class,
org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class,
org.springdoc.webmvc.ui.SwaggerConfig.class,
org.springdoc.core.SwaggerUiConfigProperties.class,
org.springdoc.core.SwaggerOAuthProperties.class,
org.springframework.autoconfigure.jackson.JacksonAutoConfiguration.class})
class OpenApiConfig implements WebMvcConfigurer {
}
Related
Setup
I use a Spring Boot app from the Initializr with Jersey dependency included and add io.swagger.core.v3:swagger-jaxrs2:2.1.13 as an additional dependency. Then I create the following ResourceConfig (registering other resource classes omitted for brevity):
#Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
this.registerClasses(
OpenApiResource.class
);
}
}
When I start the application and have a look at the generated API spec at http://localhost:8080/openapi.json, I find two paths:
GET /application.wadl/{path} and
GET /application.wadl
In Swagger UI, it looks like this:
When I send a request to the WADL endpoint, I get a 404 response in this setup. I already tried to disable the WADL feature with this line, but the spec still contains the two paths:
this.property(ServerProperties.WADL_FEATURE_DISABLE, true);
Question
How do I disable or hide these two paths in the OpenAPI spec properly?
May be you can try packages-to-scan property
springdoc:
packages-to-scan:
- com.myapp.appName.controller
I'm new in kotlin spring boot,write simple rest web service:
#SpringBootApplication
open class SpringKotlinWsApplication{
#GetMapping("/getUser")
fun getUser()= User("sample","sample")
}
fun main(args: Array<String>) {
runApplication<SpringKotlinWsApplication>(*args)
}
now configure local tomcat server on my computer,and when run the project and try to access that with this url:
http://localhost:4040/getUser
get this error:
HTTP Status 404 – Not Found
Type Status Report Message Not found Description The origin server did
not find a current representation for the target resource or is not
willing to disclose that one exists.
how can i solve that problem?
My TOMCAT configuration image here
You forgot to add #RestController annotation
#RestController
#SpringBootApplication
open class SpringKotlinWsApplication{
#GetMapping("/getUser")
fun getUser() = User("sample","sample")
...
I'm using spring-boot 1.5.0 RELEASE with swagger 2.6.1. I've added #EnableSwagger2 annotation on my spring boot application and defined a #Bean of type Docket. I've not used #EnableWebMvc annotation anywhere. I've excluded swagger-ui.html from security. When i call /v2/api-docs, i get the correct response JSON. But when i call /swagger-ui.html, it fails with HTTP 206. In chrome, it fails with Failed - No file. In console it shows the following error - Resource interpreted as Document but transferred with MIME type multipart/byteranges: "http://localhost:8080/swagger-ui.html".
Related question:
Spring Boot Remove Whitelabel Error Page
For my case,
I disabled whitelabel by setting whitelabel.enabled = false, and I also exclude ErrorMvcAutoConfiguration. It worked in regular spring boot service. But I deployed the same service on PCF cloud foundry, then spring still want to redirect error to /error page.
Any help and suggestion is welcome.
Edit:
I added exclude annotation on Application, then it works on PCF.
Previously I added exclude configuration in application.yml, then it didn't work on PCF
You need to create a separate endpoint /error and then handle it in the method. I would suggest you to maintain a separate controller infact. My code would look something like this
#RestController
#RequestMapping(path = "/error")
public class ErrorController {
#ApiOperation(value = "Error Page", notes = "Error Page")
#GetMapping
public String error() {
return "Some Error Occurred and I will Graciously show the Error"
}
}
It turns out circuit breaker service set exclusion property first, than local application.yml didn't take effect. If I add exclusion property in repo, then it take preference.
I feel this is kind of spring bug, since exclusion is list, it should include all items, instead of taking the first configuration only.
How to use propeties in application.properties in SpringBoot 2.0.0.M7 App?
I have foloowed thedocumentation, but I dont know if I need to use OAuth2ClientProperties excplicitly
One more thing, the documentation doesn't according wih the autocompletion about
syntax parameter
my application.properies :
spring.security.oauth2.client.provider.verimi.authorization-uri=https://verimi.com/dipp/api/oauth/authorize
spring.security.oauth2.client.provid
spring.security.oauth2.client.registration.verimi.scope=login
spring.security.oauth2.client.registration.verimi.authorization-grant-typeer.verimi.tokenUri=https://verimi.com/dipp/api/oauth/token
spring.security.oauth2.client.registration.verimi.client-id=dipp
spring.security.oauth2.client.registration.verimi.clientSecret=G|41|0an18ZIs_w
spring.security.oauth2.client.registration.verimi.provider=verimi=authorization_code
OAuthConfig :
#Configuration
#EnableOAuth2Client
class OAuth2Config {
// What do I need to add ?
#Bean
fun oauth2RestTemplate(oauth2ClientContext: OAuth2ClientContext,
details: OAuth2ProtectedResourceDetails): :/* <--Error here : not bean found*/ OAuth2RestTemplate = OAuth2RestTemplate(details, oauth2ClientContext)
}
THX
Verimi does not use plain OAuth2 but OpenID Connect which uses OAuth2 as authorization protocol. A few days ago I managed to make the official Verimi Spring Boot sample work. If this might help you I have pushed it in Github.