简体   繁体   English

从未使用带有@RequestMapping的类

[英]Class with @RequestMapping is never used

I'm trying to write REST server, using this video example (careful, russian speech). 我正在尝试使用视频示例(谨慎的俄语演讲)编写REST服务器。 In the example, when lecturer writes @RequestMapping above controller class, class becomes in use. 在该示例中,当讲师在控制器类上方编写@RequestMapping时,该类将被使用。 But in my case, controller class "is never used", and when I started tomcat server with my controller and going on page http://localhost:8000/app/remind/get , I get this error: No mapping for GET /app/remind/get 但是在我的情况下,控制器类“从未使用过”,当我使用控制器启动tomcat服务器并进入页面http:// localhost:8000 / app / remind / get时 ,出现了此错误: GET /没有映射应用程序/提醒/获取

This is my controller code: 这是我的控制器代码:

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

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseBody
    public String getReminder(){
        return "my reminder";
    }
}

And this is my WebConfig.java 这是我的WebConfig.java

@Configuration 
@EnableWebMvc
@ComponentScan("com.fillooow.remindme.server")
public class WebConfig extends WebMvcConfigurerAdapter {
}

So, can you explain, why my class "is never used" and what am I missing? 那么,您能否解释一下,为什么我的班级“从未使用过”,我想念什么?

EDIT My problem was wrong context in configuration file ("/" instead of "/app") 编辑我的问题是配置文件中的上下文不正确(“ /”,而不是“ / app”)

尝试如下所示的端点

 http://localhost:8000/reminder/get

Suggestion: try @GetMapping; 建议:尝试@GetMapping; be sure you're using the correct URL: 确保您使用正确的URL:

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

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

... and ... ...和...

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

ALSO: I'm not sure about your context root ("app") or your port ("8000" vs. "8080"). 另外:我不确定您的上下文根目录(“ app”)或端口(“ 8000”与“ 8080”)。

POSSIBLE ALTERNATIVE: 可能的替代方案:

http://localhost:8080/reminder/get

ADDITIONAL SUGGESTION: Enable debugging 其他建议:启用调试

logging.level.org.springframework=DEBUG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM