Spring boot 學習 四:spring boot 設定檔 application.yml

來源:互聯網
上載者:User

標籤:serve   set   一個   lang   組合   tco   圖解   函數   ota   

一 關於連接埠

      spring boot的預設連接埠是8080, 如果想更改的話,在設定檔中做如下配置。ServerProperties.class會去讀取這個值。

server:  port: 8081

      另外一種方法是:如果你只是想在啟動的時候修改一次連接埠號碼的話,可以用命令列參數來修改連接埠號碼。配置如下:java -jar 打包之後的SpringBoot.jar  --server.port=8000

二   @RestController(spring還有另外一個註解 @Controller)

       即@RestController =   @ResponseBody +   @Controller的組合註解。

        如果返回的是邏輯視圖的名稱,需要顯示頁面,則要使用@Controller, 並配合視圖解析器(resolver)來進行頁面渲染;

        如果直接返回JSON,則可以使用 @RestController。

三 @Autowired

  這個註解就是spring可以自動幫你把bean裡面引用的對象的setter/getter方法省略,它會自動幫你set/get。

  @Autowired 注釋,它可以對類成員變數、方法及建構函式進行標註,完成自動裝配的工作。 通過 @Autowired的使用來消除 set ,get方法。

  當 Spring 容器啟動時,AutowiredAnnotationBeanPostProcessor 將掃描 Spring 容器中所有 Bean,當發現 Bean 中擁有 @Autowired 注釋時就找到和其匹配(預設按類型匹配)的 Bean,並注入到對應的地方中去.

Spring boot 學習 四:spring boot 設定檔 application.yml

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.