Spring-boot / Maven simple “Hello World” application

The complete code for this application:

In this example I’ll try to show how to create a simple console application to print out the traditional “Hello World” message using spring-boot on a Maven project. I’ll try to keep it as simple as possible for now and I’ll most likely use this code as base for new posts.

Let’s start with the pom.xml file.

This is a simple console application so, for now, we only need “spring-boot-starter” as dependency.

You can also notice that I included a few plugins. The most important for now is the spring-boot-maven-plugin which will allow us to run the project with the “mvn spring-boot:run” Maven directive.

And now the main class:

That’s it.

The annotation @SpringBootApplication is a convenience annotation that implies a few others like @Configuration, @EnableAutoConfiguration and @ComponentScan. In more complex projects you most likely will declare each one individually to set a few parameters.

Now just execute the “mvn spring-boot:run” directive to run your application or “mvn package” to create a executable JAR file.

See ya!

You may also like...

Leave a Reply

%d bloggers like this: