Хост 8080 выдает ошибку 404

Приложение запускается успешно и перенаправляет информацию в нужный хост, но хост выдает

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sat Dec 06 01:02:47 KRAT 2025 There was an unexpected error (type=Not Found, status=404).

Я предполагала, что проблемы в путях в @GetMapping, но правка не исправила проблему

мой HomeController

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

    @GetMapping("/")
    public String home() {
        return "index";
    }
}

MessageController

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class MessageController {

    @GetMapping("/messages")
    public String helloWorld() {
        return "index"; // или другой шаблон
    }

    @PostMapping("/messages")
    @Respo

nseBody
        public String postMessage(@RequestBody String message) {
            // Обработка сообщение
            return "Сообщение получено: " + message;
        }
    }

TaskController

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TaskController {
    private List<Task> taskList = new ArrayList<>();

    @GetMapping("/tasks")
    public String index(Model model) {
        model.addAttribute("tasks", taskList);
        return "index";
    }

    @PostMapping("/addTask")
    public String addTask(@ModelAttribute Task task) {
        taskList.add(task);
        return "redirect:/";
    }

    @GetMapping("/deleteTask/{id}")
    public String deleteTask(@PathVariable Long id) {
        taskList.removeIf(task -> task.getId().equals(id));
        return "redirect:/";
    }

    @PostMapping("/updateTask/{id}")
    public String updateTask(@PathVariable Long id, @RequestParam boolean completed) {
        for (Task task : taskList) {
            if (task.getId().equals(id)) {
                task.setCompleted(completed);
                break;
            }
        }
        return "redirect:/";
    }
}

в пом вроде бы все нормально, зависимости все есть:

<dependencies>
    <!-- Основной стартовый зависимость для веб-приложений: включает Spring MVC, Tomcat и прочее -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Зависимость для шаблонов Thymeleaf -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <!-- Тестовая зависимость -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

файл Индекс также корректный, брала в самом задании к проекту, но на всякий случай прилагаю

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>ToDo Tracker</title>
</head>
<body>
<h1>ToDo List</h1>
<ul>
    <!-- Здесь будут отображаться задачи -->
    <li th:each="task : ${tasks}">
        <span th:text="${task.title}"></span>
        <span th:text="${task.description}"></span>
        <span th:text="${task.completed ? 'Completed' : 'Pending'}"></span>
        <a th:href="@{/deleteTask/{id}(id=${task.id})}">Delete</a>
        <form th:action="@{/updateTask/{id}(id=${task.id})}" method="post"
              style="display:inline;">
            <input type="hidden" name="completed" value="true">
            <button type="submit">Mark as Completed</button>
        </form>
    </li>
</ul>
<h2>Add New Task</h2>
<form th:action="@{/addTask}" method="post">
    <label for="title">Title:</label>
    <input type="text" id="title" name="title">
    <label for="description">Description:</label>
    <input type="text" id="description" name="description">
    <button type="submit">Add Task</button>
</form>
</body>
</html>

Ответы (1 шт):

Автор решения: Анастасия

Пробовала разные способы решений проблемы: добавляла классы обработки ошибок, файлы для них, пробовала смену юрл, это не помогало исправить ошибку.

Получилось решить проблему добавлением настройки в ключ спринг в application.yaml:

spring:
  application:
    name: demo
  thymeleaf:
    prefix: classpath:/templates/
    suffix: .html

Возможно, кому-то эта информация будет полезна.

→ Ссылка