Basic Spring Boot application always giving 404/Whitelabel error

34 Views Asked by At

My basic Spring Boot application is somehow returning only 404 on all endpoints and i'm unable to figure out why

Main file

@SpringBootApplication
@EnableJpaRepositories("com.employee.*")
@ComponentScan(basePackages = { "com.employee.*" })
@EntityScan("com.employee.*")   
public class EmployeeApplication {

public static void main(String[] args) {
    SpringApplication.run(EmployeeApplication.class, args);
}

EmployeeController.java

@RestController
@RequestMapping("/employees")
public class EmployeeController {

@Autowired
private EmployeeService employeeService;

@GetMapping("/healthcheck")
public String healthCheck() {
    return "success";
}

@GetMapping("/all")
public ResponseEntity<List<Employee>> getAllEmployees() {
    List<Employee> employees = employeeService.getAllEmployees();
    return new ResponseEntity<>(employees, HttpStatus.OK);
}

The server starts up fine without issues and no errors in the logs but whatever url I try to hit, whether http://localhost:8080/employees/healthcheck or http://localhost:8080/employees/all they all return 404. Not sure what i'm missing here

1

There are 1 best solutions below

0
AramCodes On

try removing all annotations in the main file except @SpringBootApplication and if that doesn't work try using the constructor injection instead of @Autowired.