0

Использую SpringBoot + thymeleaf, проект стартует без ошибок, но при заходе на localhost:8080 в браузере отображает ошибку Whitelabel Error Page.

pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

WebController.java

public class WebController {

@Value("${welcome.message:test}")
private String message = "Hello world";

@RequestMapping("/")
public String welcome(Map<String, Object> model) {
    model.put("message",this.message);
    return "welcome";
}

}

src/main/resources/templates/welcome.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
 <head>
  <meta charset="UTF-8">
  <title>Spring Boot Thymeleaf Hello World Example</title>
 </head>
<body>
 <div>
    <h1>Spring Boot Web Thymeleaf Example</h1>
    <h2>
        <span th:text="'Message: ' + ${message}"></span>
    </h2>
  </div>
 </body>
</html>

application.properties

welcome.message: Hello Mkyong

Подскажите, что я не правильно делаю.

1 ответ 1

0

Проблема была в том, что не указал аннотацию @Controller + изменил @RequestMapping("/") на @GetMapping

1
  • 1
    можно ещё @RequestMapping(value = "/", method = GET)
    – Komdosh
    7 мая 2018 в 10:57

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.