Spring Boot from entry to mastery - project construction

Spring Boot greatly simplifies the development of Java projects. If you want to develop a java project before, you need to install tomcat or other container plug-ins. However, tomcat has been integrated in Spring Boot, so it is very convenient to start the project. In addition, there are many default configurations in the development of Spring Boot, which helps us save a lot of time.

Quick start of Spring Boot project

In idea, file -- > New -- > Project

image

Select Spring Initializr

image

Fill in the basic project information of your maven project, such as groupId and artifact, and then select web - > Web in dependency to finish.

image

The directory structure is as follows:

image

Run DemoApplication.java directly to run the project.

Next let's analyze the dependencies in pom.xml.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>

   <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

   <version>2.1.2.RELEASE</version>

    <relativePath/>

</parent>

<groupId>com.example</groupId>

 <artifactId>demo</artifactId>

<version>0.0.1-SNAPSHOT</version>

 <name>demo</name>

  <description>Demo project for Spring Boot

 <description>Demo project for Spring Boot</description>

<properties>

<java.version>1.8</java.version>

</properties>

<!--Basically all spring boot All projects must refer to dependencies to ensure that they will not stop after project startup-->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>
</dependency>
  <!--Dependencies used in testing-->
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-test</artifactId>
     <scope>test</scope>
     </dependency>
     </dependencies>
     <build>
    <plugins>
  <!--Able to Maven To provide Spring Boot The support of is Spring Boot Application provides execution Maven The possibility of operation can Spring Boot    Application packaged as executable jar or war file-->
  <plugin>

 <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  </plugin>
  </plugins>
  </build>
  </project>

There is also an important file in Spring Boot: the application.properties/yml/yaml file.

The configuration in the project is no longer in the previous xml form, but written in this file. Spring Boot has provided us with many default configurations.

We have built a Spring Boot framework without any operation at all. In the next chapter, we will continue to learn more about Spring Boot step by step.

Tags: Spring Maven Java xml

Posted on Tue, 03 Dec 2019 05:48:19 -0500 by m@tt