Issue
I created a new controller with request mapping "/route" but no matter whatever i do I am unable to reach the endpoint localhost:8080/route
. I always get 404.
How can I access the endpoint route without getting 404?
@RestController
public interface RouteController {
@ApiOperation(value = "Add a route details to adapter", nickname = "addroute", notes = "Add route details to the table and Send it to ATLAS", tags = {
"route", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful Insertion into DB and Proceded for Transformation"),
@ApiResponse(code = 405, message = "Invalid Input") })
@RequestMapping(value = "/route", produces = { "application/json" }, consumes = {
"application/json" }, method = RequestMethod.POST)
public ResponseEntity<Void> createData(
@ApiParam(value = "Route Array", required = true) @Valid @RequestBody RouteArray routeArray) ;
}
Implementation class
public class RouteControllerImpl implements RouteController {
@Autowired
private RouteService routeService;
@Override
public ResponseEntity<Void> createData(@ApiParam(value = "Route Details", required = true) @Valid @RequestBody RouteArray routeArray) {
return new ResponseEntity<Void>(routeService.transformRoute(routeArray));
}
}
Solution
You need to change a few things in your implementation. You should not use @RestController with your OpenAPI api, but rather use @Api annotation. You should use @RestController on the class implementing this API.
@Validated
@Api(
value = "route",
description = The Controller API"
)
public interface RouteController {
@ApiOperation(value = "Add a route details to adapter", nickname = "addroute", notes = "Add route details to the table and Send it to ATLAS", tags = {
"route", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful Insertion into DB and Proceded for Transformation"),
@ApiResponse(code = 405, message = "Invalid Input") })
@RequestMapping(value = "/route", produces = { "application/json" }, consumes = {
"application/json" }, method = RequestMethod.POST)
public ResponseEntity<Void> createData(
@ApiParam(value = "Route Array", required = true) @Valid @RequestBody RouteArray routeArray) ;
}
Implementation:
@RestController
public class RouteControllerImpl implements RouteController {
@Autowired
private RouteService routeService;
@Override
public ResponseEntity<Void> createData(@Valid RouteArray routeArray) {
return new ResponseEntity<Void>(routeService.transformRoute(routeArray));
}
Answered By - KnockingHeads