Spring Boot MVC with Maven

The primary motivation behind developing Spring Boot is to simplify the process for configuring and deploying the spring applications. Spring Boot will get rid of all the fuss involved on configuring the dependencies for building the enterprise applications. In Spring based applications, configurations are loaded with a bunch of XML files, now these configurations should not be maintained in a separate file which is extra work for the developers. Developers need to focus on only writing the application while Spring Boot will simplify the deployment process by packaging and deploying application without any explicit configurations.

You may also read Spring Boot MVC with Tiles and AJAX and http://www.roytuts.com/spring-mvc-and-jdbc-crud-with-zero-xml/

More information can be found here http://projects.spring.io/spring-boot/

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

Create stand-alone Spring applications
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
Provide opinionated ‘starter’ POMs to simplify your Maven configuration
Automatically configure Spring whenever possible
Provide production-ready features such as metrics, health checks and externalized configuration
Absolutely no code generation and no requirement for XML configuration

The reference guide includes detailed descriptions of all the features http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/.


The following configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven 3 installed and configured
Spring 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse

Step 1. Create a maven based web project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.


Now enter the required fields (Group Id, Artifact Id) as shown below

Group Id : com.roytuts
Artifact Id : spring-boot

The final project looks like below

spring boot

Step 2. Modify the pom.xml file as shown below.

Step 3. If you see JRE System Library[J2SE-1.5] then change the version by below process

Do right-click on the project and go to Build -> Configure build path, under Libraries tab click on JRE System Library[J2SE-1.5], click on Edit button and select the appropriate jdk 1.8 from the next window. Click on Finish then Ok.

Change also the Compiler compliance level as 1.8 from Java -> Compiler.

Step 4. Now when the build process finished then delete web.xml file from WEB-INF

Step 5. Create application.properties file put under src/main/resources

Step 6. Create a directory called views under src/main/webapp directory for putting jsp views.

Step 7. Create MySQL table teacher in database roytuts

Step 8. Dump some data into the table

Step 9. Now create POJO class and mapper class which will map Java object to database table teacher

Step 10. Create Mapper class for mapping database table row to Java object

Step 11. Create DAO class for querying database table

Step 12. Create the service class for processing logic or business logic

Step 13. Create Spring controller class which will handle user request and response

Step 14. Now create teacher.jsp file under webapp/views directory for displaying single teacher details

Step 15. Create teachers.jsp file under webapp/views directory for displaying all teachers details

Step 16. Create add.jsp file under webapp/views directory for adding new teacher

Step 17. Create update.jsp file under webapp/views directory for updating new teacher

Step 20. Now create a main class which will run the spring-boot application

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes. The @SpringBootApplication indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning.

The @ComponentScan annotation tells Spring to search recursively through the com.roytuts.spring.boot package and its children for classes marked directly or indirectly with Springs @Controller, @Service, @Repository etc. annotations.

Step 21. Now run the SpringBootTeacherApplication class and when the application successfully deployed onto the server you will see below output in the console.

Please look at the console carefully, you would see, the server has been started on port 8080 with context path “/”.

Step 22. Now hit the URL http://localhost:8080/teachers , you will below output in the browser

spring boot

You can try to update, delete from the links.

Step 23. If you hit http://localhost:8080/teacher/16, you would get below output

spring boot

Step 24. You can add new teacher using URL http://localhost:8080/addTeacher

Thanks for reading.


Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

3 thoughts on “Spring Boot MVC with Maven

  1. Good lecturer, good course. So far so good. Could please post some tutorials how to configure spring tiles and AjaxUrl Based View Resolver using Spring boots.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.