I came across an issue that Spring Boot app works for the endpoint that has recently been changed.
Controller:
@RestController
@RequiredArgsConstructor
@RequestMapping("/tasks")
public class TaskController {
private final TaskService taskService;
@GetMapping("/")
public List<Task> getAllTasks() {
return taskService.getAllTasks();
}
@GetMapping("/id/{id}")
public Task getTaskById(@PathVariable Long id) {
return taskService.getTaskById(id).orElseThrow(() -> new RuntimeException("No task was found with id: " + id));
}
}
When I am trying to access /id/{id}
like http://localhost:8080/api/tasks/id/1
the page can't be found.
But while using /{id}
by going to http://localhost:8080/api/tasks/1
(which is my old approach) it works, even though the mapping in the code is now different.
I am using Maven as a build tool and tried to provide a new clean compile, but that does not seem to work. Recently I was messing around with project file structure and moving classes into separate folders, which might be the case.
App:
@SpringBootApplication
@EntityScan(basePackages =
{"com.bl4kee.kanbanboard.entities.common","com.bl4kee.kanbanboard.entities.task"})
@EnableJpaRepositories(basePackages = {"com.bl4kee.kanbanboard.dao"})
public class KanbanBoardApplication {
public static void main(String[] args) {
SpringApplication.run(KanbanBoardApplication.class, args);
}
}
Given project structure presented below.