我正在尝试使用此视频示例(小心,俄语语音)编写 REST 服务器。在示例中,当讲师在控制器类上方编写 @RequestMapping 时,类将被使用。但在我的情况下,控制器类“从未使用过”,当我用我的控制器启动 tomcat 服务器并进入页面http://localhost:8000/app/remind/get 时,我收到这个错误:没有映射 GET /应用程序/提醒/获取这是我的控制器代码:@Controller@RequestMapping("/reminder")public class ReminderController { @RequestMapping(value = "/get", method = RequestMethod.GET) @ResponseBody public String getReminder(){ return "my reminder"; }}这是我的 WebConfig.java@Configuration @EnableWebMvc@ComponentScan("com.fillooow.remindme.server")public class WebConfig extends WebMvcConfigurerAdapter {}那么,你能解释一下,为什么我的课程“从未使用过”,我错过了什么?编辑 我的问题是配置文件中的错误上下文(“/”而不是“/app”)
2 回答

富国沪深
TA贡献1790条经验 获得超9个赞
建议:试试@GetMapping; 确保您使用的是正确的 URL:
@Controller
@RequestMapping("/reminder")
public class ReminderController {
@GetMapping(value = "/get")
@ResponseBody
public String getReminder(){
return "my reminder";
}
}
... 和 ...
http://localhost:8000/app/reminder/get
另外:我不确定您的上下文根(“应用程序”)或您的端口(“8000”与“8080”)。
可能的选择:
http://localhost:8080/reminder/get
附加建议:启用调试
logging.level.org.springframework=DEBUG
添加回答
举报
0/150
提交
取消