Whitelabel错误页面-Spring Boot应用程序中的错误

问题描述 投票:0回答:1

即使在映射URL之后,在运行Spring Boot Application时,我也得到了“ Whitelabel Error Page”。

我已经提到了我的application.properties文件和一个控制器文件

application.properties file

server.port=8087
server.servlet.context-path=/starts

spring.h2.console.enabled=true

---------------------------------------------

TestController.java file

package com.example.firstproject.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.firstproject.Entity.Employee;
import com.example.firstproject.Service.EmployeeService;

@RestController

public class TestController {
@Autowired
EmployeeService empService;

    @RequestMapping("/save")
    public int test(@RequestBody Employee emp) {
        return empService.saveEmployee(emp);
        //return 0;
    }
    @RequestMapping("/getAll")
    public List<Employee> home() {
        return empService.getAll();
    }

    @RequestMapping("/test")
    public String test()
    {
        return "success";
    }
}

我还附上了我在运行项目时遇到的错误图片Whitelabel Error Page

我应该如何消除此错误?

java eclipse spring-boot microservices spring-tool-suite
1个回答
0
投票

您的/ save映射是POST请求,需要Employee对象。您无法从浏览器URL调用它。浏览器调用仅是GET请求。您应该使用诸如Postman之类的工具来发送POST请求。

© www.soinside.com 2019 - 2024. All rights reserved.