为什么我在SpringBoot中找不到404?

laawzig2  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(254)

我正试图通过以下抽象类向客户端发送字符串:

public abstract class Command{
    protected String description;

    public Command(String description) {
        this.description=description;
    }

    public abstract void execute(String text);

    public abstract String writeToClient( String text);
}

以及扩展这个抽象类的类:

@CrossOrigin
@RestController
@RequestMapping("api/")
public class uploadCommand extends Command{

    public uploadCommand() {
        super("1. upload a time series csv file\n");
    }

    @Override
    public void execute(String text) {
        text= writeToClient("Please upload your local train CSV file.\n");
    }

    @CrossOrigin
    @GetMapping(path = "/ret/text", produces = MediaType.TEXT_PLAIN_VALUE)
    @Override
    public String writeToClient(@RequestParam(defaultValue = "text") String text) {
        return text;
    }

当我用 Postman 寄信时 GET 请求:

http://localhost:6033/api/ret/text

我得到以下回应:

{"timestamp":"2021-02-22T14:16:40.526+00:00","status":404,"error":"Not Found","message":"","path":"/api/ret/text"}

如果从客户端运行它,则会出现以下错误:

Access to XMLHttpRequest at 'http://localhost:6033/api/ret/text' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

xhr.js:178 GET http://localhost:6033/api/ret/text net::ERR_FAILED

Uncaught (in promise) Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:83)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题