Spring is a framework designed to build Java applications quickly. Applications built with Spring are flexible because the framework supports many other frameworks, such as Hibernate, Struts, and EJB.
The folks who created Spring provided a page to quickly bootstrap an application. To create your first Spring app, open a browser and navigate to https://start.spring.io/, as shown in Fig. 1.
At the "Project" field, select the Build Automation tool you want your app to use. Maven and Gradle are both popular tools, so your choice may come down to which tool you and your team are most familiar with.
At the "Language" field, select your language of choice. Java, Kotlin, and Groovy all compile to Java bytecode and run on the Java Virtual Machine (JVM), so they are all compatible with Spring.
At the "Spring Boot" field, select the version of Spring you wish to use. Generally, you should select the latest version that is not a "SNAPSHOT" version. SNAPSHOT versions are created for development and testing and may not be as stable.
At the "Group" field, enter a group ID for the project. This is similar to a project's default namespace in .NET.
At the "Artifact" field, enter a descriptive name for the project.
The "Name" field defaults to your Artifact ID. It is usually fine to accept this default.
At the "Description" field, enter a brief description of your project.
The "Package name" field defaults to the Group ID, followed by ".", followed by the Artifact ID. It is usually fine to accept this default.
At the "Packaging" field, specify whether you want Spring to generate JAR files or WAR files when packaging the application. A WAR file is only appropriate for a web application, while a JAR file can be used for any application. This article explains the differences between the two. I typically select JAR files.
At the "Java" field, select the version of Java your application will use. For a new project, you will likely want to choose the latest Long Term Release (LTS) version of Java. As of this writing, that is version 17. Exceptions would be
- You need a feature available in a more recent version
- You are creating an application that must be compatible with a project built using an older version
Click the [ADD DEPENDENCIES] button to add more dependencies to your application. A dialog displays a list of available dependencies, as shown in Fig. 2.
For example, you can select "Spring Web" if you intend to build a REST API. You can always add dependencies after the project is created, but this wizard makes it easier to do so.
Click the [GENERATE] button to generate the project. The wizard will generate all the necessary folders and files, compress them into a ZIP file, and download that file.
Extract the ZIP file into a location on your hard drive. The structure will look similar to that shown in Fig. 3.
Open the project in your favourite Integrated Development Environment (IDE). This is a good starting point for your application.
In this article, I showed you how to create a new Spring application using start.spring.io.
You can find the final code here.