首页 > 解决方案 > 带有 Rest API 404 的 Spring Boot

问题描述

API 在没有 spring-boot 的情况下工作,但在 spring-boot 下,它不是。

@RequestMapping("/operationsOnEmployee")

    @RestController
    public class OperationsOnEmployee {

        @Autowired
        EmployeeFacade employeeFacade;

        @GetMapping(produces = "application/json")
        public List<Employee> getEmployee() {
            System.out.println("hello");
            return employeeFacade.getAllEmployee();
        }

应用程序属性

server.port:8080
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect
spring.datasource.url=jdbc:mysql://localhost:3306/company
spring.datasource.username=root
spring.datasource.password=root

    "timestamp": "2019-08-01T11:34:07.631+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/operationsOnEmployee"

标签: springrestspring-boot

解决方案


利用

@GetMapping(value= "/operation", produces = "application/json")

称呼

GET:   localhost:8080/operationsOnEmployee/operation

另外,请确保您没有application.properties中定义任何路径

server.servlet.context-path= #some path

推荐阅读