1. Build a simple SpringBoot project

1. Environmental preparation

1. The development tool is IDEA

2. The Maven version is 3.5.0. Attached to the configuration file of maven

The private server of Alibaba Cloud is used, and the configuration is as follows:

{

<mirror>

      <id>alimaven</id>

      <mirrorOf>central</mirrorOf>

      <name>aliyun maven</name>

      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

    </mirror>

}

3. The JDK version is 1.8.0

Second, build the project

1. There are two ways to build a springboot project with idea. The first one can be directly created by the creation method provided by springboot. In this way, the jar packages that need to be relied on in the project pom file created and processed are all configured and can be directly created. To develop. The creation window and project structure are as follows:

 

 

Note: This method should require the computer to be able to connect to the network

The second way is to create a maven project, and then manually add springboot dependencies. Here we mainly talk about the dependencies that need to be added and some configuration files that are needed.

The manually created project structure is as follows: It should be noted that the location of application.properties and startup class SpringBootStart.java must be accurate

 

The configuration of the pom file is as follows: the red configuration is the main spring boot configuration

{

<?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>

    <groupId>spring-boot-demo</groupId>
    <artifactId>create-spring-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
    </dependencies>
</project>

}

The configuration of application.properties is:

{

#项目名称
spring.application.name=spring-boot-demo

#占用端口
server.port=8080

#数据库连接
spring.datasource.url=jdbc:mysql/localhost:3306/chenly
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.name=root
spring.datasource.password=root
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

}

After the configuration is complete, compile and start the SpringBootStart class as soon as the compilation is correct. The following is a log of successful startup:

 

Access through a browser: http://localhost:8080/index The execution result is as follows:

 

The above interface shows that the spring boot project is successfully constructed.

Three, the problems encountered during the construction process

1. Since the location of the SpringBootStart class is not at the same level as the control layer, the following error is displayed when the service is started and accessed through the browser:

 

Solution:

1. The position of the startup class SpringBootStart and the control layer can be leveled as follows:

 

2. Add package scanning related configuration in the startup class

 

Guess you like

Origin blog.csdn.net/u013804636/article/details/115261918