Spring is just displaying an html page

Problem:

Using Spring 4, I get this when visiting a webpage

Whitelabel Error Page

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

Fri Aug 15 16:41:29 BST 2014
There was an unexpected error (type=Not Found, status=404).

What I have:

I have this main class:

// src/main/java/abc/Main.java
package abc;

import abc.web.WebAppConfig;
import org.springframework.boot.SpringApplication;

public class Main {
    public static void main(String[] args) {
        SpringApplication.run(WebAppConfig.class);

    }
}

Then I have this WebAppConfig.class (currently with only some configuration annotations):

// src/main/java/abc/web/WebAppConfig.java
package abc.web;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan
@EnableAutoConfiguration
public class WebAppConfig {

}

And this controller is HomeController.java:

// src/main/java/abc/web/HomeController.java
package abc.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

@Controller
@RequestMapping("/")
public class HomeController {

    @RequestMapping(method = GET)
    public String home() {
        System.out.println("HELLO !!");
        return "home";
    }
}

Hello! displayed in logs.

And finally, I have the html file in src/main/java/abc/webapp/home.html, with only some html tags, including the pc tag Hello, world!.

Question:

I understand that I am missing a way to render the view, but I was looking for a couple of questions about stackoverflow and have not yet found a solution.

Can someone explain how I can get Spring to display a webpage? What am I missing?

Thanks in advance:)

+4
3

Spring Boot Thymeleaf , . classpath,

compile("org.springframework.boot:spring-boot-starter-thymeleaf")

gradle.

maven, :

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

, home.html ( ), /resources/templates.

.

+8

: " Spring Boot -?" : home.html src/main/resources/static/. /home.html.

.

+5

You probably did not configure the template engine and did not find the resolution. See the thimeleaf example here http://www.thymeleaf.org/doc/thymeleafspring.html Since the thymeleaf template is valid HTML code and vice versa, you can use it.

0
source

All Articles