I have problem with Spring Boot MVC and views. When I go on localhost:9090, I've got page with "index" written and not my index.html page like view. Can you tell my what the problem is ? Thanks in advance.
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
MainController
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class MainController {
@RequestMapping(method = RequestMethod.GET)
public String index() {
return "index";
}
}
Application.yml src/main/resources/application.yml
spring:
data:
rest:
basePath: /api
mvc:
view:
prefix: /webapp/
suffix: .html
server:
port: 9000
My index.html is in : src/main/webapp/index.html
Maybe useless but : Application.java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
UPDATE: I put index.html in src/static/index.html Ok but I have same problem with :
I add in my pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
In map.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p>this is the map</p>
</body>
MapController
@Controller
@RequestMapping("/map")
public class MapController {
@RequestMapping(method = RequestMethod.GET)
public String index() {
return "map";
}
}
Map.html is in wepapp. When I go to localhost:9090/map, I've the following error on chrome :
This application has no explicit mapping for /error, so you are seeing this as a fallback.
And in eclipse I've got this error :
Error resolving template "map", template might not exist or might not be accessible by any of the configured Template Resolvers
Map maybe should be in webapps/templates? I really dont know.
SOLUTION : Thanks guys ! Controller
@Controller
@RequestMapping("/map")
public class MapController {
@RequestMapping(method = RequestMethod.GET)
public String index() {
return "map";
}
}
And the views must be in src/main/resources/templates/map.html and NOT in wepapp/templates/map.html map.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Bienvenue sur le portail historique intéractif - Amysto</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="main">
<div class="row">
<p>Il faut mettre la map ici</p>
</div>
</div>
</body>
<script src="./foundation/js/vendor/jquery.js"></script>
<script src="./js/menu.js"></script>
</html>
I can't upvote so I let you do guys :)