我正在嘗試使用此視頻示例(小心,俄語(yǔ)語(yǔ)音)編寫(xiě) REST 服務(wù)器。在示例中,當(dāng)講師在控制器類(lèi)上方編寫(xiě) @RequestMapping 時(shí),類(lèi)將被使用。但在我的情況下,控制器類(lèi)“從未使用過(guò)”,當(dāng)我用我的控制器啟動(dòng) tomcat 服務(wù)器并進(jìn)入頁(yè)面http://localhost:8000/app/remind/get 時(shí),我收到這個(gè)錯(cuò)誤:沒(méi)有映射 GET /應(yīng)用程序/提醒/獲取這是我的控制器代碼:@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 {}那么,你能解釋一下,為什么我的課程“從未使用過(guò)”,我錯(cuò)過(guò)了什么?編輯 我的問(wèn)題是配置文件中的錯(cuò)誤上下文(“/”而不是“/app”)
2 回答

富國(guó)滬深
TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
建議:試試@GetMapping; 確保您使用的是正確的 URL:
@Controller
@RequestMapping("/reminder")
public class ReminderController {
@GetMapping(value = "/get")
@ResponseBody
public String getReminder(){
return "my reminder";
}
}
... 和 ...
http://localhost:8000/app/reminder/get
另外:我不確定您的上下文根(“應(yīng)用程序”)或您的端口(“8000”與“8080”)。
可能的選擇:
http://localhost:8080/reminder/get
附加建議:?jiǎn)⒂谜{(diào)試
logging.level.org.springframework=DEBUG

慕運(yùn)維8079593
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
嘗試如下端點(diǎn)
http://localhost:8000/reminder/get
添加回答
舉報(bào)
0/150
提交
取消