繁体   English   中英

邮差404 Spring Rest API

[英]Postman 404 spring rest api

这是我的应用程序配置

spring.data.mongodb.host=192.168.56.1
spring.data.mongodb.port=27017
spring.data.mongodb.database=test

server.port=8080
spring.application.name=test
server.servlet.context-path=/test

这是我的控制器代码:

package com.example.crud;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;



@RestController
@RequestMapping("/crud")
public class CrudOperation {

   @GetMapping("/getAll")
   public String getMethod() {      
       return "Get Datas success";
   }

   @PostMapping("/save")
   public String saveMethod() {     
       return "save successfully";
   }

   @PutMapping("/update")
   public String update() {     
    return "Update Data success";
   }

   @DeleteMapping("/remove")
   public String delete() {     
       return "Delete Data success";
   }
}

我无法访问Postman中的任何方法,我不断收到404错误或方法未找到错误。 我尝试仅通过简单的返回就运行该应用程序,但仍然遇到了问题。 我究竟做错了什么? 如果我的问题不够说明性,请在评论中让我知道,请勿将其标记为重复。

改变你的

server.servlet.context-path=/test

server.servlet.contextPath=/test

暂无
暂无

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

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