从未使用带有@RequestMapping的类

时间:2018-10-29 22:37:22

标签: java spring spring-mvc

我正在尝试使用this视频示例(小心,俄语)来编写REST服务器。 在该示例中,当讲师在控制器类上方编写@RequestMapping时,该类将被使用。但是在我的情况下,控制器类“从未使用”,当我使用控制器启动tomcat服务器并进入页面http://localhost:8000/app/remind/get时,出现以下错误:没有GET / app / remind / 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 个答案:

答案 0 :(得分:0)

尝试如下所示的端点

#s=1

答案 1 :(得分:0)

建议:尝试@GetMapping;确保您使用正确的URL:

@Controller
@RequestMapping("/reminder")
public class ReminderController {

    @GetMapping(value = "/get")
    @ResponseBody
    public String getReminder(){
        return "my reminder";
    }
}

...和...

http://localhost:8000/app/reminder/get

也:我不确定您的上下文根目录(“ app”)还是端口(“ 8000”对“ 8080”)。

可能的替代方法:

http://localhost:8080/reminder/get

其他建议:启用调试

logging.level.org.springframework=DEBUG