Project skeleton
Last updated
Last updated
SPRING INITIALIZR provides a visual web UI to start a Spring Boot project. You can select which starter will be added in the project you will create.
Open https://start.spring.io, search Web, Security, JPA, Validation in the Dependencies input box, select the items in the dropdown menus.
Then press ALT+Enter
or click Generate button to download the generated codes in zip archive.
Extract the files into your local system.
As a start point, it only includes a few files.
The Maven project configuration pom.xml, and several maven wrapper files which is like Gradle wrapper and use to download a specific maven for this project.
A Spring Boot specific Application
class as the application entry.
A dummy test for the Application
class.
Open the pom.xml, it looks like:
The package type is jar, which means it will include an embedded tomcat at build time. You can start the application via command line java -jar app.jar
.
The parent module is spring-boot-starter-parent
which is a BOM(Bill of material) and includes the declaration of Spring Boot dependencies. Just add the dependencies you want to use under the dependencies
node.
Every starter will handle transitive dependencies. Besides those starters we selected, it also includes a starter for test purpose which will add the popular test dependencies transitively, such as hamcrest, assertj, mockito etc.
spring-boot-maven-plugin
allow you run the project in the embedded Tomcat.
Another important file is the entry class of this sample application.
@SpringBootApplication
is a meta-annotation, which is a combined annotation with @EnableAutoConfiguration
, @ComponentScan
and @SpringBootConfiguration
.
@EnableAutoConfiguration
enables the auto configuration detection by default.
@SpringBootConfiguration
is similar with @Configuration
, it indicates the application is a Spring Boot application, and only allow one @SpringBootConfiguration
in an application.
@ComponentScan
defines the scope to find components, by default if not specify the package, it will scan the annotated class as base package. So it is recommended to put the Application
in the root package.
Besides these, nothing! Where are the configuration files?
Spring Boot internally used plenty of auto-configuration mechanism to simplfy configurations for Spring developers. For this project, it configures a simple BASIC authentication by default. If you add a H2 database or other JDBC drivers, it will configure a DataSource and transaction manager automatically.
Till now, if you added some dependencies into pom.xml
, you can start to code now. It is the quick way to prototype your application.
Although Spring Boot provides auto-configuration feature, but it does not prevent you to customize your configuration.
In the sample codes, there are some custom configuration classes.