The main purpose of SpringBoot is to simplify configuration files. Java programs can be run with a small amount of configuration, and its powerful automatic configuration features help developers easily implement configuration assembly. By introducing SpringBoot’s starter, desired functions can be achieved without additional configuration.

Currently, there are three ways to build SpringBoot project:

  • Created through Spring Initializr
  • Create a project using IDEA
  • Manually creating a project

Official generation tool

The Spring team provides a very convenient web page for generating the SpringBoot project. Open a browser and go to Spring Initializr:

Project generated parameter list:

  • Project: Project type (support for Maven and Gradle build tools)
  • Language: Main Language of the project can be selected as required Java, Kotlin, Groovy
  • SpringBoot: indicates the SpringBoot version
  • ProjectMatedata:GroupandArtifactSuch as configuration,
  • Dependencies: Project Dependencies

After parameter setting, click Generate to download the project. After completion, import the project using IDEA and open the project synchronization to run.

IDEA Creation Project

Newer IDEA versions have built-in SpringBoot project plug-in, which is also created using Spring Initializr to create projects. The creation process is as follows:

  • Open theIDEAThe development tools
  • choosefile -> new -> projectThe menu
  • Select in the new dialog boxSpring Initializr
  • Click on theNextTo create a SpringBoot project

Finally, add the main method to start the application:

@SpringBootApplication
@Slf4j
public class SpringEnvApplication {



	public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(SpringEnvApplication.class, args); }}Copy the code

Manually create a SpringBoot project

In addition to the above two methods, you can manually create a SpringBoot project by creating an empty Maven project using IDEA and specifying SpringBoot dependencies. The basic process is as follows:

  • Open theIDEAThe development tools
  • choosefile -> new -> projectThe menu
  • Select in the new dialog boxMavenn
  • Click on theNextComplete the project creation as prompted

After the project is created, open the pom. XML file and set the parent configuration of pom. XML:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.0. RELEASE</version>
</parent>
Copy the code

Add the SpringBootMaven package plug-in:

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

Copy the code

Add the main method to start the application:

@SpringBootApplication
@Slf4j
public class SpringEnvApplication {



	public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(SpringEnvApplication.class, args); }}Copy the code

The complete POM.xml file:

<?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 https://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.2.0. RELEASE</version>
		<relativePath/> <! -- lookup parent from repository -->
	</parent>
	<groupId>com.csbaic.arch</groupId>
	<artifactId>spring-env</artifactId>
	<version>0.0.1 - the SNAPSHOT</version>
	<name>spring-env</name>
 
	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
	</dependencies>

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

</project>

Copy the code

With the parent and plug-in set up, you can use SpringBoot to create your application.





Every day, Architecture Digest publishes a great article in the field of architecture, covering application architecture (high availability, high performance, high stability), big data, machine learning and other hot fields of first-tier Internet companies.