The spring-boot-starter-parent provides you all maven defaults required for any spring project.
Since we are developing a web application, we also need to add spring-boot-starter-web dependency.
This will include additional dependencies such Spring boot, tomcat etc which are required for this application.
If you notice, we did not provide any version for specific components. You just need to provide version no.(1.5.3.RELEASE) for spring boot.step 3: Create a package named “org.arpit.java2blog.springboot”
create a controller class named “HelloWorldController.java”

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

packageorg.arpit.java2blog.springmvc.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

@Controller

publicclassHelloWorldController{

@RequestMapping("/helloworld")

publicModelAndView hello(){

StringhelloWorldMessage="Hello world from java2blog!";

returnnewModelAndView("hello","message",helloWorldMessage);

}

}

As request first goes to dispatcherServlet and it redirects to the controller class. Here @Controller depicts that this is our controller class. @RequestMapper is used to map incoming HTTP request to handler method(hello() in above controller).So hello() method of HelloWorldController.java will handle GET request from dispatcher.So when we have url of

1

2

3

4

http://localhost:8080/helloworld or

http://localhost:8080/helloworld.html

above method will get called.

Step 4: Create a package named “org.arpit.java2blog”
create a class named “SpringBootHelloWorldApplication.java”

1

2

3

4

5

6

7

8

9

10

11

12

13

14

packageorg.arpit.java2blog;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

publicclassSpringBootHelloWorldApplication{

publicstaticvoidmain(String[]args)

{

SpringApplication.run(SpringBootHelloWorldApplication.class,args);

}

}

We have just added @SpringBootApplication and it does all the work.
Let’s understand more about this annotation.@SpringBootApplication is an annotation that adds all of the following:

@Configuration makes the class as a source of bean definitions for the application context.@EnableAutoConfiguration enables Spring boot to add beans presents in classpath setting and various property setting.
Normally you would add @EnableWebMvc for a Spring MVC application, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath.
This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.@ComponentScan tells Spring to look for other components, configurations, and services in the default package, allowing it to find the controllers.
If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.

Step 5: Create a property file named application.properties as below and put it in src/main/resoures.

spring.mvc.view.prefix: /WEB-INF/
spring.mvc.view.suffix: .jsp

Above two properties are very much similar to used in springmvc-dispatcher-servlet.xml in Spring MVC example.

Step 10: Let’s test the application now.
As Spring uses embedded tomcat, you can access the project using http://localhost:8080/index.jsp.
When you click on above link, you will get below screen.
That’s all about Spring boot web application example using JSP. If you find any issue with this project, please put a comment.