In Spring Boot, BeanNameViewResolver bean is registered by default, that means we can use a View's bean name as a view name by default. In a plain Spring MVC application we have to explicitly register this bean ourselves (example here).
Example
We are going to create a custom View in this example.
@Controller
public class MyController {
@GetMapping("/")
public String handle(Model model) {
model.addAttribute("msg", "test msg from controller");
return "myCustomView";
}
}
Java Config and main class
@SpringBootApplication
public class ExampleMain {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(ExampleMain.class, args);
}
}
Output
Example Project
Dependencies and Technologies Used:
Spring Boot 1.5.8.RELEASE Corresponding Spring Version 4.3.12.RELEASE
spring-boot-starter-web : Starter for building web, including RESTful, applications using Spring
MVC. Uses Tomcat as the default embedded container.