我在使@RequestMapping工作时遇到问题,我收到以下日志;你能帮我理解日志吗?
启动时记录:
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
访问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
应用程序属性:
server.servlet.context-path=/ruler
server.port=80
休息 Controller :
@RestController
public class myController {
private final MedicalService medicalService;
@Autowired
public myController(MedicalService medicalService) {
this.medicalService = medicalService;
}
@RequestMapping(value="/test")
public String testRest()
{
return "Yay";
}
}
没有 web.xml。
最佳答案
找到了我的问题的答案 here ,这是因为项目结构,而不是配置。
应用程序包应该像com.app
,然后 Controller 将是com.app.controller
。
关于java - @RequestMapping 不起作用 - 没有找到处理程序方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51966987/