Swagger request url is returning response under controller @RequestMapping(value="/**", method = RequestMethod.GET)
See original GitHub issueSwagger is working fine, until i created a new controller to handle all the not mapped requests like below. https://github.com/stormpath/spring-mvc-rest-exhandler/blob/master/example/src/main/java/com/stormpath/blog/spring/mvc/rest/exhandler/DefaultController.java
//Create Request
@RequestMapping(value="/**", method = RequestMethod.GET)
public @ResponseBody ResponseEntity handleGetRequest(HttpServletRequest request) {
return ResponseEntity.status(HttpStatus.ACCEPTED)
.body("No resource found");
}
Once i introduce this RequestMapping /**,
now /localhost:8080/WEBAPP/swagger-ui.html also falling under this handler method. If i comment this above /**
mapping code then swagger is again starts working.
To resolve this issue; I have tried like
- Adding @ApiIgnore for this new controller.
- Moved this controller to outside of swagger component scan
- swagger component-scan made specific to not including this new controller.
- Path is restricted with WEBAPP new Docket(DocumentationType.SWAGGER_2).paths(ant(“/WEBAPP/**”))
I didn’t able to make swagger to work. But other regular controller in my code is working. Please help me; by making swagger to work along with this “/**” handling.
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages="com.datami.hpong")
public class SwaggerConfig {
@Bean
public Docket accountingApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("hpong_group")
.apiInfo(hpongApiInfo())
.select()
.paths(hpongApiPaths())
.build()
.enableUrlTemplating(false);
}
private ApiInfo hpongApiInfo() {
return new ApiInfoBuilder()
.title("Hpong APIs")
.description("Hpong Api description")
.version("1.0")
.build();
}
private Predicate<String> hpongApiPaths() {
return ant("/**");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.datami.hpong" />
<mvc:annotation-driven />
<mvc:resources location="classpath:/META-INF/resources/"
mapping="swagger-ui.html" />
<mvc:resources location="classpath:/META-INF/resources/"
mapping="swagger.json" />
<mvc:resources location="classpath:/META-INF/resources/webjars/"
mapping="/webjars/**" />
<bean id="swagger2Config"
class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" />
<mvc:annotation-driven enable-matrix-variables="true" />
<bean name="/applicationSwaggerConfig" class="com.datami.hpong.swagger.SwaggerConfig" />
</beans>Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
maybe support override RequestMapping value?
wildcard endpoints are not supported.