Build Spring Boot application in just 5 minutes


Spring Boot

Spring Boot is Spring's convention-over-configuration solution for creating stand-alone, production-grade Spring-based Applications that you can "just run".

You can use Spring Boot to create Java applications that can be started using java -jar or more traditional war deployments.

Features:

  • Create stand-alone Spring applications
  • Embed Tomcat or Jetty 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
In this example we will see that just using two files Application.java and pom.xml we can create a sprint boot application. The advantage of spring boot is that it takes care of all the configurations and you can focus on your application code rather than spending time configuring your application

Find this project on Github

https://github.com/javacodenet/springBootDemo

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javacodenet</groupId>
<artifactId>spring-boot</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
view raw pom.xml hosted with ❤ by GitHub

Application.java

package com.javacodenet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class Application {
@RequestMapping("/")
public String homePage(){
return "Welcome to home page";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

Run your application from IDE









Alternatively,  you can use spring boot maven plugin by executing 'run' goal spring-boot:run










Also, You can package your application mvn package








You can also run jar from command line, 'cd' into your target folder and execute  java -jar spring-boot-1.0-SNAPSHOT.jar







Output


Comments

Popular posts from this blog

Generate PDF From XML Or Java Object Using Apache FOP

Generate Random values in Spring boot

Generate/Read an Excel file in Java using Apache POI