当前位置:网站首页>02_ Springboot starter case

02_ Springboot starter case

2022-06-24 23:06:00 Book opens autumn maple

1. Create an empty project Empty Project

2. The project file name is SpringBoot

3. choice Create create

 

4. choice File --》New --》Moudle Create a module

5. Select the information configuration associated with naming this item

6. choice Web --》Spring Web

7. Introduction to project structure

(1) .mvn|mvnw|mvnw.cmd: Use script operations to perform maven Relevant command , Less used in China , Deleting

(2) .gitignore: Use version control tools git When , Set something that ignores submission

(3) static|templates: The following is the directory where the files are stored in the template technology

static: Put some static content css js img

templates: Template based html

(4)application.properties:SpringBoot Configuration file for , Many integrated configurations can be in this file To configure , for example :Spring、springMVC、Mybatis、Redis etc. . It's empty at the moment

(5) Application.java:SpringBoot The entry of program execution , Execute... In the program main Method ,SpringBoot And it started , Auto start built in tomcat function

8. Introduce SpringBoot Start the entry class

9. pom.xml Default auto configuration details

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

    <!-- Inherit SpringBoot A parent project of the framework , All self-developed Spring Boot Must inherit -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <!-- Current project GAV coordinate -->
    <groupId>com.suke.springboot</groupId>
    <artifactId>springboot-first</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!--maven Project name , You can delete -->
    <name>001-springboot-first</name>
    <!--maven Project description , You can delete -->
    <description>001-springboot-first</description>

    <!--maven Attribute configuration , It can be passed elsewhere ${} Reference in different ways -->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--SpringBoot frame web Project start depends on , Automatically associate other dependencies through this dependency , We don't need to add one by one -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--SpringBoot The testing of the framework depends on , for example :junit test , If you don't need it, you can delete -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <!-- Build : compile -->
    <build>
        <!-- Which resource to compile -->
        <resources></resources>

        <!-- plug-in unit -->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.7.0</version>
            </plugin>
        </plugins>
    </build>

</project>

10. Run input localhost:9001/001-springboot-first/springBoot/say According to successful

11.  Introduction case summary and analysis

Spring Boot Our father depends on spring-boot-starter-parent After configuration , The current project is Spring Boot project

spring-boot-starter-parent It's a Springboot Our father depends on , Development SpringBoot All programs need to inherit the parent project , It is used to provide relevant Maven Default dependency , After using it , frequently-used jar Package dependency can eliminate version To configure

Spring Boot What defaults are available jar Package dependency , You can view the pom file

If you do not want to use a default dependent version , Can pass pom.xml The attribute configuration of the file overrides each dependency , Like coverage Spring edition

<properties>

     <spring.version>5.0.0.RELEASE</spring.version>

</properties>

@SpringBootApplication The note is Spring Boot The core notes of the project , The main function is to turn on Spring Automatic configuration , If in Application Class , Then it won't start SpringBoot Program

main The method is a standard Java programmatic main Method , The main function is to serve as the entrance for the project startup and operation

@Controller And @ResponseBody It's still what we were before Spring MVC, because Spring Boot It still uses our Spring MVC + Spring + MyBatis Other framework

原网站

版权声明
本文为[Book opens autumn maple]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241714023647.html