spring boot 文檔學習筆記day01

来源:https://www.cnblogs.com/yueguangmoliya/archive/2018/03/14/8564017.html
-Advertisement-
Play Games

1.在pom.xml中使用spring-boot-starter-parent的作用: Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The paren ...


1.在pom.xml中使用spring-boot-starter-parent的作用:

Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:

  • Java 1.8 as the default compiler level.
  • UTF-8 source encoding.
  • A Dependency Management section, inherited from the spring-boot-dependencies pom, that manages the versions of common dependencies. This dependency management lets you omit <version> tags for those dependencies when used in your own pom.
  • Sensible resource filtering.
  • Sensible plugin configuration (exec plugin, Git commit ID, and shade).
  • Sensible resource filtering for application.properties and application.yml including profile-specific files (for example, application-dev.properties and application-dev.yml)

 

2.pom.xml裡面有哪些配置,太多了,網址:

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-dependencies/pom.xml

 

3.啟動類的位置最好在最外層的包中:

We generally recommend that you locate your main application class in a root package above other classes. The @EnableAutoConfiguration annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the @EnableAutoConfiguration annotated class is used to search for @Entity items.

Using a root package also lets the @ComponentScan annotation be used without needing to specify a basePackage attribute. You can also use the @SpringBootApplication annotation if your main class is in the root package.

The following listing shows a typical layout:

com

 +- example

     +- myapplication

         +- Application.java

         |

         +- customer

         |   +- Customer.java

         |   +- CustomerController.java

         |   +- CustomerService.java

         |   +- CustomerRepository.java

         |

         +- order

             +- Order.java

             +- OrderController.java

             +- OrderService.java

             +- OrderRepository.java


4.儘量使用java配置,避免使用xml配置

You need not put all your @Configuration into a single class. The @Import annotation can be used to import additional configuration classes. Alternatively, you can use @ComponentScan to automatically pick up all Spring components, including @Configuration classes.

If you absolutely must use XML based configuration, we recommend that you still start with a @Configuration class. You can then use an @ImportResource annotation to load XML configuration files.

 

5.自動配置

You need to opt-in to auto-configuration by adding the @EnableAutoConfiguration or @SpringBootApplication annotations to one of your @Configuration classes.,只添加到一個即可

 

 

6.排除不需要自動配置的類

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

或者

you can also control the list of auto-configuration classes to exclude by using the spring.autoconfigure.exclude property.

 

7.Bean註入容器

If you structure your code as suggested above (locating your application class in a root package), you can add @ComponentScan without any arguments. All of your application components (@Component, @Service, @Repository, @Controller etc.) are automatically registered as Spring Beans.

 

8. @SpringBootApplication代替常用幾個的註解

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes

 

9.開發工具

The spring-boot-devtools module can be included in any project to provide additional development-time features.

<dependencies>

               <dependency>

                               <groupId>org.springframework.boot</groupId>

                               <artifactId>spring-boot-devtools</artifactId>

                               <optional>true</optional>

               </dependency>

</dependencies>

支持代碼修改後重新載入啟動,如果不需要:

If you do not want to use the restart feature, you can disable it by using the spring.devtools.restart.enabled property. In most cases, you can set this property in your application.properties (doing so still initializes the restart classloader, but it does not watch for file changes).

If you need to completely disable restart support (for example, because it does not work with a specific library), you need to set the spring.devtools.restart.enabled System property to false before calling SpringApplication.run(…​), as shown in the following example:

public static void main(String[] args) {

               System.setProperty("spring.devtools.restart.enabled", "false");

               SpringApplication.run(MyApp.class, args);

}

在開過程中經常修改但是不想啟動,application.properties裡面設置指定的文件修改才重啟:

#重啟的文件resouces文件夾中新建文件restart.trigger並設置

spring.devtools.restart.trigger-file=restart.trigger

這樣只有在restart.trigger這個文件更改時才重新啟動

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Facade模式也叫外觀模式,是由GoF提出的23種設計模式中的一種。Facade模式為一組具有類似功能的類群,比如類庫,子系統等等,提供一個一致的簡單的界面。這個一致的簡單的界面被稱作facade。 外觀模式的角色和職責 1、Facade:為調用方定義簡單的調用介面。 2、Clients:調用者。 ...
  • 經典的Java面試題(第二部分),這部分主要是與Java Web和Web Service相關的面試題。 96、闡述Servlet和CGI的區別? 答:Servlet與CGI的區別在於Servlet處於伺服器進程中,它通過多線程方式運行其service()方法,一個實例可以服務於多個請求,並且其實例一 ...
  • 10、頁面側邊欄:使用自定義模板標簽 我們的博客側邊欄有四項內容:最新文章、歸檔、分類和標簽雲。這些內容相對比較固定,且在各個頁面都會顯示,如果像文章列表或者文章詳情一樣,從視圖函數中獲取然後傳遞給模板,則每個頁面對應的視圖函數里都要寫一段獲取這些內容的代碼,這會導致很多重覆代碼。更好的解決方案是直 ...
  • 忙得忘了更新了 經過了半年多的糾結終於還是一衝動買了一隻緬因貓,又給自己找了個長期工作,我也是夠能作的了! 貓和狗完全不一樣,各種不一樣,不交流,沒有反應,沒有表情, 還要給它清理大小便,它到處爬,把我蘋果原裝數據線咬壞了, 白天睡晚飯上上竄下跳,還經常用爪子撩狗,養了這幾個禮拜, 我現在渾身上下都 ...
  • 回顧 int/float/str/list/tuple/dict 整數型和浮點型是不可變的,不是序列 字元串是不可變的,是序列 列表是可變的,是序列 元組是不可變的,是序列 字典是可變得,但不是序列 集合的基本概念 集合是基本的數學概念,它是集合論的研究對象,指具有某種特定性質的事物的總體,(在最原 ...
  • 給定一個有1編號。進行搜索時,假設我們總是從編號最小的頂點出發,按編號遞增的順序訪問鄰接點。 輸入格式: 輸入第1行給出2個整數N(0<N≤10)和E,分別是圖的頂點數和邊數。隨後E行,每行給出一條邊的兩個端點。每行中的數字之間用1空格分隔。 輸出格式: 按照{v1v2.....vk}的格式,每行輸 ...
  • 內容:判斷質數 持續更新 # __author: _nbloser # date: 2018/2/4 import math def is_prime(number): num_sqrt = int(math.sqrt(number)) for i in range(2, num_sqrt + 1) ...
  • 使用模板有助於將業務邏輯與表現邏輯分開,更易於維護。模板是已經建立的網頁代碼,其中部分動態數據需要在請求的上下文中用具體值替換。 flask中使用了Jinja2模板引擎,儲存在templates文件夾中。 使用 {{ name }} 占位 模板的渲染 模板的渲染即用真實值取代模板中的占位變數的過程。 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...