The more you work with Spring Boot the more you understand the benefits of it.
The one thing you always hear when someone talks about Spring Boot is, that you don´t have to handle the different setups for and in your project.
But a lot of people start a bit wrong with their Spring Boot projects. Many of them just start with a pom.xml, in which they implement (step by step) their different dependencies, plugins and so on.
I want to show you a more elegant and efficient way to setup your project.
Let´s say we just want to create a new project that works with REST, and handles a database connection via JPA. Furthermore we want to handle our entities with lombok.
Of course you can just use the IDE of your choice. But there are different, good alternatives.
A very common and often used way to create the basic structure of your project is by using the web initializer. We just define:
- project type (maven / gradle)
- dependencies we want to have
Using the Web interface is the most comfortable way, I think. But there is still another one.
Spring Boot CLI
For installing the Spring Boot CLI please visit this little tutorial.
Using the CLI initializer
With a working Spring Boot CLI you now can use the Initializer.
The basic command for initiating a Spring Boot project is just
It download a demo.zip which contains only the absolut basics of a spring boot application. Nothing special I think.
Init with dependencies
Because we need some more dependencies, we add the ones we need with the -d command
spring init -dweb,jpa,h2,lombok
If you´d run this command you will get again the demo.zip folder and if you would look at the pom.xml you can see., that all the dependencies we need are added.
But let´s move on
Init with a few commands
spring init -dweb,jpa,h2,lombok --build gradle -p jar javadevcornerDemo -x
Let me explain all that things to you
- –build gradle:
By default the application is based on maven, now we could use gradle.
- -p jar: (Equivalent to –packaging jar)
By default a Spring Boot application is packed as a jar. You can pack it here as war if you want to.
The artifactId of our application
- -x: (Equivalent to –extract)
We don´t want to extract our .zip by foot, we´ll do it automatically
Thanks for reading and have fun using the different types of setting up your Spring Boot Project.