Standalone Application Using Spring Boot

In this post, we will discuss creating Spring Boot standalone application.



Spring Boot makes it easy to create stand-alone, production-grade Spring-based applications.Spring Boot provides various starters for building standalone or more traditional war deployments.We will create Spring Boot standalone application by implementing CommnadLineRunner interface.


1. Project Creation 

There are multiple ways to create Spring Boot application.

We will use Spring initializr to create our project structure.

If you are starting with Spring Boot, read our article on building Spring Boot application.


2. The Maven Dependency

The spring-boot-starter is the only required dependency to build our standalone application.Here is our pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
   <description>Spring Boot Standalone application</description>
      <relativePath />
      <!-- lookup parent from repository -->

Let’s discuss few interesting points from the pom.xml file

  • Packaging for our application set to jar.
  • spring-boot-starter is the only required dependency.


3. Service Class

For this post, We are creating HelloService bean which will print greeting message to the calling API.

package com.javadevjournal.service;

public interface HelloService {
    void hello();

package com.javadevjournal.service;

public class DefaultHelloService implements HelloService {

    public void hello() {
       System.out.println("Hello from Hello Service");


4. Spring Boot Main Class

To bootstrap our application, let’s create our main class and annotate it with @SpringBootApplication annotation.

public class SpringBootStandaloneApplication implements CommandLineRunner {

	public static void main(String[] args) {, args);

	private HelloService helloService;

	public HelloService helloService(){
		return  new DefaultHelloService();

	public void run(String... args) throws Exception {

The use of CommandLineRunner is not required but it provides several advantages during the application startup and management.

  • CommandLineRunner executes after the application context loaded so we could use it to check if certain beans exist or required values correctly initialized.
  • Provide control of the system startup process.


5. Run Application

Running Spring Boot application is similar to any other Java programme, we need to run the main method.We can also run the application by executing mvn spring-boot: run command.

5.1 Run Application

Spring Boot provides an option for creating a completely self-contained executable jar file to run in production.To create an executable jar, we need spring-boot-maven-plugin in our pom.xml file (check section 2 for detail).Run mvn package command to create an executable jar.

$ mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building standalone-application 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Results:
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ standalone-application ---
[INFO] Building jar: /deployment/standalone-application/target/standalone-application-0.0.1-SNAPSHOT.jar
[INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:repackage (default) @ standalone-application ---
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.311 s
[INFO] Finished at: 2018-03-13T22:58:12-07:00
[INFO] Final Memory: 34M/306M
[INFO] ------------------------------------------------------------------------

On successful execution, we can find an executable jar (standalone-application-0.0.1-SNAPSHOT.jar) in the target directory.To run the application, use java -jar command

$ java -jar target/standalone-application-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::        (v2.0.0.RELEASE)

 2018-03-13 23:03:05.232  INFO 38482 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-13 23:03:05.246  INFO 38482 --- [           main] c.j.SpringBootStandaloneApplication      : Started SpringBootStandaloneApplication in 0.949 seconds (JVM running for 1.355)
Hello from Hello Service



Spring Boot provides a number of options to create a production-ready application.In this post, We covered building and running Spring Boot standalone application.

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of