猿问

从不使用带有 @RequestMapping 的类

我正在尝试使用此视频示例(小心,俄语语音)编写 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”)


守候你守候我
浏览 209回答 2
2回答

富国沪深

建议:试试@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

慕运维8079593

尝试如下端点 http://localhost:8000/reminder/get
随时随地看视频慕课网APP

相关分类

Java
我要回答