1. Overview

Every application should require its default landing page or we can say default index or welcome page. The user will land to default index page when the user types the only domain name. Spring boot provides very easy ways to default index page.

Solution 1: index.html page inside public

create an index.html page inside resources/public/index.html

Solution 2: index.html page inside static

create an index.html page inside resources/static/index.html

Solution 3: Using controller Mapping

Create a controller with@RequestMapping("/") which will return view name but for this requires any view configuration. Here is spring boot jsp example

package com.javadeveloperzone.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

 * Created by Java Developer Zone on 19-07-2017.
public class IndexController {
    public String index() {
        return "Spring Boot Example";

2. Example:

In this example, we have createdindex.html page inside resources/public/index.html page.

Spring boot index page example

Spring boot index page example


2.1 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <description>This is example of spring boot index page or default landing page</description>
    <!-- Inherit defaults from Spring Boot -->
    <!-- Package as an executable jar -->

2.2 index.html

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Spring boot index page example</title>
    This is spring boot index page available inside resources/static/index.html

2.3 SpringBootConfig

package com.javadeveloperzone;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
 * Created by JavaDeveloperZone on 19-07-2017.
@ComponentScan // Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute
public class SpringBootConfig {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootConfig.class, args);            // it wil start application

2.4 Output:

Now type,http://localhost:8080 It will land to default index or landing or welcome page.


Spring boot index page example - output

Spring boot index page example – output

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *