question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger request url is returning response under controller @RequestMapping(value="/**", method = RequestMethod.GET)

See original GitHub issue

Swagger 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

  1. Adding @ApiIgnore for this new controller.
  2. Moved this controller to outside of swagger component scan
  3. swagger component-scan made specific to not including this new controller.
  4. 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:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
xiaoyao9184commented, Jan 17, 2020

maybe support override RequestMapping value?

1reaction
dilipkrishcommented, Jul 5, 2018

wildcard endpoints are not supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring MVC @RequestMapping Annotation Example with ...
@RequestMapping with @RequestParam for URL parameters: Sometimes we get parameters in the request URL, mostly in GET requests.
Read more >
Swagger configured in Spring Boot shows only methods with ...
Your answer is correct. This exception appears because in one of my controllers I have parameter "java.util.Map" without any generics. When I ...
Read more >
Using the Spring @RequestMapping Annotation
In this post, I show you how to use the Spring MVC @RequestMapping annotation to configure how Spring MVC maps web requests to...
Read more >
RestController example with Spring Boot and Swagger
A basic example of RestController in a Spring Boot application using @GetMapping and ... GET) and @RequestMapping(method = RequestMethod.
Read more >
Web on Servlet Stack - Spring
In turn, the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found