Reputation: 493
I am trying to integrate swagger2 with my spring boot application but when I try to open swagger-ui page in the browser it gives me following error on the console:
Resolved exception caused by Handler execution: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "swagger-ui.html"
Here is my SwaggerConfig Class:
@EnableSwagger2
@PropertySource("classpath:swagger.properties")
@ComponentScan(basePackageClasses = TestController.class)
@Configuration
public class SwaggerConfiguration {
private static final String SWAGGER_API_VERSION="1.0";
private static final String LICENSE_TEXT ="License";
private static final String title ="Merchant API";
private static final String description ="Restful APIs for merchant";
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title(title)
.description(description)
.license(LICENSE_TEXT)
.version(SWAGGER_API_VERSION)
.build();
}
@Bean
public Docket merchantApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()
.build();
}
}
Here is my controller class :
@RestController
@RequestMapping("/test")
@Api(value="MerchantControllerAPI",produces = MediaType.APPLICATION_JSON_VALUE)
public class TestController {
@RequestMapping(path="{/id}", method = RequestMethod.GET)
@GetMapping("/")
@ApiOperation("Testing")
@ApiResponses(value={@ApiResponse(code=200, message="Ok",response=String.class )})
public String getSomething(@PathVariable("id") String id){
return "HelloWorld";
}
}
I following this tutorial. Anybody here who have faced similar problem? Please help me out.
Blockquote
Upvotes: 1
Views: 3675
Reputation: 991
Please remove @PropertySource("classpath:swagger.properties")
also change your TestController as shown below
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/test")
@Api(value = "MerchantControllerAPI", produces = MediaType.APPLICATION_JSON_VALUE)
public class TestController {
@RequestMapping(path = "/{id}", method = RequestMethod.GET)
@GetMapping("/")
@ApiOperation("Testing")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Ok", response = String.class)})
public String getSomething(@PathVariable("id") String id) {
return "HelloWorld";
}
}
Upvotes: 1