简体   繁体   中英

Spring Boot with Rest API 404

API working without spring-boot, but with spring-boot, it is not.

@RequestMapping("/operationsOnEmployee")

    @RestController
    public class OperationsOnEmployee {

        @Autowired
        EmployeeFacade employeeFacade;

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

application.properties

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" 

Use

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

Call

GET:   localhost:8080/operationsOnEmployee/operation

Also, make sure you don't have any path defined in application.properties

server.servlet.context-path= #some path

Try to provide mapping URL inside @GetMapping to map your method as :

@GetMapping("/mappingURL")

GET URL : localhost:8080/operationsOnEmployee/mappingURL

If not clean the project and re-run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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