I am trying to design a rest api, and below is my controller code.
when i invoke http://localhost:8080/ the response is fine, but if i hit http://localhost:8080/api/ca it thorws javax.servlet.ServletException: No adapter for handler [...CaDetailController@48224381]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
@RestController("/api")
public class CaDetailController {
private static final Logger logger = LoggerFactory.getLogger(GetClassLoader.class.getClass());
@Autowired
CaService caService;
@RequestMapping(path = "/ca", method = RequestMethod.GET)
public @ResponseBody List<CaDetail> getCorporateActions() {
logger.info("CaDetailController.findAllCaDetails()");
return caService.findAllCaDetails();
}
@RequestMapping(path = "/ca/{caId}", method = RequestMethod.GET)
public @ResponseBody List<CaDetail> getCorporateActions(@PathParam("caId") long caId) {
logger.info("CaDetailController.getCorporateActions() : caId : " + caId);
return caService.findAllCaDetails();
}
}
Updated controller.
@RestController
@RequestMapping("/api/ca")
public class CaDetailController {
private static final Logger logger = LoggerFactory.getLogger(GetClassLoader.class.getClass());
@Autowired
CaService caService;
@GetMapping(path = "/")
public @ResponseBody List<CaDetail> getCorporateActions() {
logger.info("CaDetailController.findAllCaDetails()");
return caService.findAllCaDetails();
}
@GetMapping(path = "/{caId}")
public @ResponseBody List<CaDetail> getCorporateActions(@PathParam("caId") Long caId) {
logger.info("CaDetailController.getCorporateActions() : caId : " + caId);
return caService.findAllCaDetails();
}
}
@RestController("/api")
is different than@RestController @RequestMapping("/api")
. – Kooky@RequestMapping(path = "/ca", method = RequestMethod.GET)
can be replaced by@GetMapping("/ca")
– Kooky@GetMapping
and adding@RequestMapping
still having same issue. – Swaney@GetMapping("/")
was causing the problem, after removing parameter'/' it worked ! Thanks !! i've got confused witht he parameter of
@restController` annotation which is actually a bean name if required to refer. – Swaney