Springcloud学习笔记36–Springboot 项目maven 常用依赖和application.yml配置(Springcloud learning notes 36 — common Maven dependencies and application.yml configuration of springboot project)

1.springboot 进行统一的版本管理

通过标签<parent>:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
    </parent>

在后面在进行引入依赖的时候,就写作为如下方式:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--<version>2.1.6.RELEASE 已经统一指定</version>-->
        </dependency>

以上的这种统一版本的管理是spring boot默认的方式。

2.构建web项目模块

核心作用:快速web应用开发

为了帮我们简化快速搭建并开发一个Web项目,Spring boot为我们提供了spring-boot-starter-web自动配置模块。

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.6.RELEASE</version>
        </dependency>

spring-boot-starter-web默认为我们提供一些SpringMVC必要的组件。

spring-boot-starter-web默认使用嵌入式的tomcat作为web容器对外提供HTTP服务。

3. Nacos实现服务注册和发现

注意:实际使用时,需要启动本地单机版nacos,具体见 https://www.cnblogs.com/luckyplj/p/15175191.html

        <!--nacos-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

4.JDBC驱动包

 mysql-connector-java 是MySQL的JDBC驱动包,用JDBC连接MySQL数据库时必须使用该jar包。

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>

5.数据库连接配置

spring.datasource.url=jdbc:mysql://{datasource host}:3306/{databaseName}
spring.datasource.username={database username}
spring.datasource.passwd={database passwd}

对应的maven 依赖:

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

6.mybatisPlus

Mybatis-Plus是一个Mybatis的增强工具,只是在Mybatis的基础上做了增强却不做改变,MyBatis-Plus支持所有Mybatis原生的特性,所以引入Mybatis-Plus不会对现有的Mybatis构架产生任何影。Mybatis-Plus又简称(MP)是为简化开发,提高开发效率而生.

        <!-- mybatisPlus 核心库 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!-- 添加 代码生成器 依赖 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!--模板引擎(mybatis-plus自动生成代码需要模板)-->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.28</version>
        </dependency>

Mybatis-plus代码生成器具体使用参考:https://www.cnblogs.com/luckyplj/p/15166224.html

Mybatis-plus操作数据库进行增删改查具体参考:https://www.cnblogs.com/luckyplj/p/15421975.html

7.数据库连接池

————————

1. Spring boot for unified version management

Via tag & lt; parent>:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
    </parent>

When introducing dependencies later, they are written as follows:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--<version>2.1.6.RELEASE 已经统一指定</version>-->
        </dependency>

The above unified version management is the default method of spring boot.

2. Build web project module

Core role: rapid web application development

In order to help us simplify and quickly build and develop a web project, spring boot provides us with the spring boot starter web automatic configuration module.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.6.RELEASE</version>
        </dependency>

Spring boot starter web provides us with some necessary spring MVC components by default.

Spring boot starter Web uses embedded Tomcat as the web container by default to provide HTTP services.

3. Nacos implements service registration and discovery

Note: in actual use, you need to start the local stand-alone version of Nacos. See https://www.cnblogs.com/luckyplj/p/15175191.html

        <!--nacos-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

4. Jdbc driver package

MySQL connector Java is the jdbc driver package of MySQL. You must use this jar package when connecting to MySQL database with JDBC.

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>

5. Database connection configuration

spring.datasource.url=jdbc:mysql://{datasource host}:3306/{databaseName}
spring.datasource.username={database username}
spring.datasource.passwd={database passwd}

Corresponding Maven dependencies:

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

6.mybatisPlus

Mybatis plus is an enhancement tool for mybatis. It is only enhanced on the basis of mybatis without change. Mybatis plus supports all the native features of mybatis. Therefore, the introduction of mybatis plus will not have any impact on the existing mybatis architecture. Mybatis plus (MP) is designed to simplify development and improve development efficiency

        <!-- mybatisPlus 核心库 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!-- 添加 代码生成器 依赖 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!--模板引擎(mybatis-plus自动生成代码需要模板)-->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.28</version>
        </dependency>

For specific use of mybatis plus code generator, refer to: https://www.cnblogs.com/luckyplj/p/15166224.html

Add, delete, modify and query the mybatis plus operation database. For details, refer to: https://www.cnblogs.com/luckyplj/p/15421975.html

7. Database connection pool