Show Topics
Hide Topics

Spring Boot with Maven and Eclipse Example


1.Open Eclipse > File > New > Maven Project



2.Tick ‘Create a simple project (skip archetype selection) ‘ check box > click Next



3. Provide Group Id (its your package), Artifact Id (project name) and click Finish pom.xml, add Spring Boot dependencies

  • spring-boot-starter-parent:  is an existing project given by spring team which contains Spring Boot supporting configuration data (just configuration data, it won’t download any jars), we have added this in a <parent> tag means, we are instructing Maven to consider our SpringBootHelloWorld project as a child to it


  • spring-boot-starter-web: Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container



5.Now right click on the application > Maven > Update Project,

if you observe the directory structure of the project, it will create a new folder named “Maven Dependencies” which contains all supporting. jars to run the Spring Boot application and the Java version also changed to 1.8.

  • if you observe pom.xml, we haven’t included version number for spring-boot-starter-web but maven downloaded some jar files with some version(s) related to spring-boot-starter-web, that’s because of Maven’s parent child relation.
  • While adding spring boot parent project, we included version as 1.5.6.RELEASE, so again we no need to add version numbers for the dependencies.  As we know spring-boot-starter-parent contains configuration meta data, this means, it knows which version of dependency need to be downloaded.  So we no need to worry about dependencies versions., it will save lot of our time.



6.create a java class with main() method, in a pakage.

  • @SpringBootApplication annotation, is the starting point for our Spring Boot application
  • run(SpringBootApp.class, args); it will bootstrapping the application

Remember, for every spring boot application we have to create a main class and that need to be annotate with @SpringBootApplication and bootstrap it.



8.Finally, right click on the application > Run As > Java Application


Download Example