日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot基础篇(二):HelloWorld细节探究

發布時間:2025/3/8 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot基础篇(二):HelloWorld细节探究 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、場景啟動器

1.1依賴

<!--Hello World項目的父工程是org.springframework.boot--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.1.RELEASE</version><relativePath/></parent><!--org.springframework.boot他的父項目是spring-boot-dependencies他來真正管理Spring Boot應用里面的所有依賴版本;Spring Boot的版本仲裁中心;以后我們導入依賴默認是不需要寫版本;(沒有在dependencies里面管理的依賴自然需要聲明版本號)--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.2.1.RELEASE</version><relativePath>../../spring-boot-dependencies</relativePath></parent>

1.2、SpringBoot場景啟動器

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

? spring-boot-starter:spring-boot場景啟動器;幫我們導入了web模塊正常運行所依賴的組件;

Spring Boot將所有的功能場景都抽取出來,做成一個個的starters(啟動器),只需要在項目里面引入這些starter相關場景的所有依賴都會導入進來。要用什么功能就導入什么場景的啟動器.

2、自動配置

package com.lizhengi;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;/*** springBootApplication:標注一個主程序類,表示這個是一個Springboot應用*/@SpringBootApplication public class HelloWorldApplication {public static void main(String[] args) {//Spring應用啟動SpringApplication.run(HelloWorldApplication.class, args);} }

@SpringBootApplication: Spring Boot應用標注在某個類上說明這個類是SpringBoot的主配置類,SpringBoot就應該運行這個類的main方法來啟動SpringBoot應用;

看一下@SpringBootApplication這個注解類的源碼

@Target({ElementType.TYPE}) //可以給一個類型進行注解,比如類、接口、枚舉 @Retention(RetentionPolicy.RUNTIME) //可以保留到程序運行的時候,它會被加載進入到 JVM 中 @Documented //將注解中的元素包含到 Javadoc 中去。 @Inherited //繼承,比如A類上有該注解,B類繼承A類,B類就也擁有該注解@SpringBootConfiguration@EnableAutoConfiguration/* *創建一個配置類,在配置類上添加 @ComponentScan 注解。 *該注解默認會掃描該類所在的包下所有的配置類,相當于之前的 <context:component-scan>。 */ @ComponentScan(excludeFilters = {@Filter(type = FilterType.CUSTOM,classes = {TypeExcludeFilter.class} ), @Filter(type = FilterType.CUSTOM,classes = {AutoConfigurationExcludeFilter.class} )} ) public @interface SpringBootApplication
  • @SpringBootConfiguration:Spring Boot的配置類;標注在某個類上,表示這是一個Spring
    Boot的配置類;
  • @SpringBootConfiguration:Spring Boot的配置類;標注在某個類上,表示這是一個Spring
    Boot的配置類;
  • @EnableAutoConfiguration:開啟自動配置功能:以前我們需要配置的東西,Spring Boot幫我們自動配置;@EnableAutoConfiguration告訴SpringBoot開啟自動配置功能;這樣自動配置才能生效;
  • @AutoConfigurationPackage:自動配置包。

總結

以上是生活随笔為你收集整理的SpringBoot基础篇(二):HelloWorld细节探究的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。