Spring Boot 项目结构冲突

问题描述

我遇到了一个问题,即 Spring Boot 应用程序适用于最近更改的端点。

控制器:

@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));
}
}

当我像 /id/{id} 一样尝试访问 http://localhost:8080/api/tasks/id/1 时,找不到页面

但是通过转到 /{id}(这是我的旧方法)使用 http://localhost:8080/api/tasks/1 时,它可以工作,即使代码中的映射现在不同。

我使用 Maven 作为构建工具并尝试提供新的干净编译,但这似乎不起作用。最近我在处理项目文件结构并将类移动到单独的文件夹中,可能就是这种情况。

应用:

@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);
 }
}

给定的项目结构如下所示。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)