rest - Spring Boot does not create the Restful WS when we give @RequestBody or @RequestHeader as a method parameter -
in our project have interface , implementing class in interface provide method signature annotated @requestmapping annotation. class implementing interface annotated @restcontroller , @requestmapping annotations , overriding methods in interface.
issue: in of methods, when give @requestbody or @requestheader parameter, spring boot not creating /v1/myapi/load url given in @requestmapping in interface. if give empty parameters creating url.
further digging in, figured out if remove @requestmapping annotations interface methods , provide in methods in controller class working irrespective of giving in method parameter.
i want know why @requestmapping provided in interface not considered when use @requestbody or @requestheader method parameter.
@controller @requestmapping("/v1/myapi/") public class mycontrollerclass implements myinterface{ @override public responseobject method1(@requestbody string request, @requestheader(name= httpheaders.authorization) string token){ } //interface class public interface myinterface { @requestmapping(method = requestmethod.post,value="/load",produces = mediatype.application_json_value) responseobject method1(@requestbody string request, @requestheader(name= httpheaders.authorization) string token) throws exception; }
the annotations must in either implementing class or in controller interface (if choose have one) in order work correctly. copied javadoc of @requestmapping:
note: when using controller interfaces (e.g. aop proxying), make sure consistently put all mapping annotations - such @requestmapping , @sessionattributes - on controller interface rather on implementation class.
Comments
Post a Comment