Springcloud學習筆記36--Springboot 專案maven 常用依賴和application.yml配置
阿新 • • 發佈:2021-11-25
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.資料庫連線配置
預設情況下,當我們沒有配置任何DataSource,SpringBoot會為我們自動配置一個DataSource,這種自動配置的方式一般適用於測試,開發還是自己配置一個DataSource的例項比較好。如果我們的工程只依賴一個數據庫,那麼,使用DataSource自動配置模組提供的引數是最方便的:
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.資料庫連線池
參考文獻: https://www.jianshu.com/p/2093dd0168b9