Reputation: 80
I am trying to generate Swagger documentation from a springboot project using Springfox and following https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api documentation.
Initially I got the error "Full authorization is required to access the resource" since I am using OAuth2 in my application. I changed the configuration to permit all the requests ending with /swagger-ui.html.
Now I have been getting "WhiteLabel error page - This application has no explicit mapping for /error" while trying to access /swagger-ui.html on my local.
I went through various posts but none of the solutions worked for me - I am not using @webmvcconfiguration which can interfere. Can anyone help?
Upvotes: 1
Views: 11795
Reputation: 109
This is how I solved my problem. Here is my detailed code, if someone want to look.
https://github.com/xbox2204/SpringBoot-JPA-Swagger
Now, I used 3.0.0-SNAPSHOT and a latest spring-boot starter project I created from here:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
spring.resources.add-mappings=true
@EnableWebMvc
@EnableSwagger2
@SpringBootApplication
@Bean
public Docket productApi() {
Contact contact =new Contact(
"Vineet Mishra",
"https://github.com/xbox2204",
"[email protected]"
);
ApiInfo apiInfo= new ApiInfoBuilder().title("VINEET SPRING-BOOT API")
.description("Spring-Boot for all")
.termsOfServiceUrl("jUST CHILL!!!")
.contact(contact)
.licenseUrl("[email protected]").version("1.0").build();
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.any())
.build();
}
http://localhost:8080/swagger-ui/index.html#
Upvotes: 1
Reputation: 584
Remove the v2 dependencies from your pom.xml or comment them out.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Add the springfox-boot-starter
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Change the URL in your browser to: http://localhost:8080/swagger-ui/index.html
The general form for the URL is:
For more info check this link that leads to the relevant documentation: https://springfox.github.io/springfox/docs/snapshot/#changes-in-swagger-ui
Upvotes: 2
Reputation: 12024
For Swagger 3.0, The URL is changed to
http://localhost:8080/swagger-ui/index.html
Upvotes: 6
Reputation: 2307
The swagger-ui.html page makes a number of calls to get all the details. If you use your browser's dev tools (usually just press F12 to open) you will see failing requests in the network tab. You'll need to permit requests to
"/v2/api-docs",
"/swagger-resources/**",
"/swagger-ui.html**",
"/webjars/**"
There's some info in the springfox docs , do a find for 'security' or 'authorization'
Upvotes: 0