2
votes

I have problem in getting the @RequestMapping to work, I get the following logs; could you please help me understand the log?

Log while booting:

DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/ruler/webjars/test]

DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /webjars/test

DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/webjars/test]

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns for request [/webjars/test] are [/webjars/, /]

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/webjars/test] are {}

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/webjars/test] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/webjars/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@52454457]]] and 1 interceptor

DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/ruler/webjars/test] is: -1

DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling

DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

Log while accessing localhost:80/ruler/test:

DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/ruler/test]

DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /test

DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/test]

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns for request [/test] are [/**]

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/test] are {}

DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/test] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@4538856f]]] and 1 interceptor

DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/ruler/test] is: -1

DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling

DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

Application.properties:

server.servlet.context-path=/ruler
server.port=80

RestController:

    @RestController
public class myController {
    private final MedicalService medicalService;

    @Autowired
    public myController(MedicalService medicalService) {
        this.medicalService = medicalService;
    }

    @RequestMapping(value="/test")
    public String testRest()
    {
        return "Yay";
    }
}

No web.xml.

3
1. show your complete controller class or atleast class declaration and annotations 2. how are you calling this endpoint and what is the url u r using? - pvpkiran
Try addin the @ResponseBody annotation to your testRest method - S.Tushinov
@S.Tushinov That is not beneficial, according to documents; using @RestController is equivalent of using @Controller and @ResponseBody - Ace
Shouldn't you be accessing the url along with the port-number? Something like localhost:8080/ruler/test - Nicholas K

3 Answers

3
votes

Found the answer to my problem here, it was because of project structure, not the configs.

App package should be like com.app then controller would be com.app.controller.

0
votes

Also You can use @GetMapping with ResponseEntity for more specific information

    @GetMapping(value = "/test")
    public ResponseEntity<String> testRest(){
        return ResponseEntity.ok("Yay");
    }
0
votes

Change

@RequestMapping(value="/test")

to

@RequestMapping(value="/test", method = RequestMethod.GET)