Introduction to Spring Boot Framework

Introduction to Spring Boot: auto-configuration, starter dependencies, embedded Tomcat, and building your first app.

What is Spring Boot ?

Fastest way of building the applications. Its check the classpath and beans, makes

assumptions what your are missing, and add that. This is a new framework from Pivotal. Its freeing developer from XML based configuration. It takes care about the configurations, so that developer can focus on business logic more and less on infrastructure.

What we need to run the Spring Boot applications ?

Below are the required software, should be installed in your system in order to run the Spring Boot applications.

Java Version

1.6 and above

Maven version

3.0 and above

How to build Spring boot project ?

Below are the three different way to build Spring Boot project.

  • Build your own maven project by keeping best practices in mind and add the dependency in pom.xml.
  • Build maven web project using any IDE and add the dependency in pom.xml
  • Using STS(Spring Tool Suite) – if you dont have STS please downloadand extract anywhere.

STS download

Follow the below steps to write the first program in Spring Boot Using STS.

Step 1

Open STS(Spring Tool Suite)

Step 2

File ->New->Spring Starter Project

New Spring Boot Project

Step 3

Provide Project Name

Spring boot project name

Step 4

Select Project type you want to build.

Spring boot project type

Step 5

Click Finish

Spring boot finish

Wait while downloading dependencies, its required internet connection.

Downloading Spring boot dependencies

Code

HelloWorldApplication.java

Java
package javaant;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloWorldApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloWorldApplication.class, args);
    }
}

HelloWorldController.java

Java
package javaant;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloWorldController {
	@RequestMapping("/hello")
	public @ResponseBody String hello(){
		return "hello";
	}

}

pom.xml

XML
4.0.0

	com.javaant
	javaant
	0.0.1-SNAPSHOT
	jar

	HelloWorld
	Spring Boot HelloWorld

	
		org.springframework.boot
		spring-boot-starter-parent
		1.2.5.RELEASE
		 
	

	
		UTF-8
		1.7
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	
	
	
		
			
				org.springframework.boot
				spring-boot-maven-plugin

How to Run?

Right click on the project -> Run As -> Spring Boot App

Now you will see the below log in console

server-started

Now open browser and type url http://localhost:8080/hello

If you see the below error please stop the server and run again.

Spring boot error

Output

hello

Note – If you do not want to download STS and you want to use another IDE you can build the project online (https://start.spring.io/)

Then download the code and import in any IDE.

Spring boot is really easy to build the project, its required very minimum configurations.

download code

About Glenna Babshire29 Articles
Java & libraries writer. Writes the Java tutorials: the language from Java 21 on, encryption, configuration and the libraries around it.