SpringBoot的Full模式與Lite模式

2021-10-17 15:26:48 字數 1368 閱讀 2390

@configuration這個註解相信大家都不陌生,配置類註解。

在springboot2中,@configuration中可以如下使用

@configuration

(proxybeanmethods =

false

)//告訴springboot這是乙個配置類 == 配置檔案

public

class

myconfig

@bean

("tom"

)public pet tomcatpet()

}

proxybeanmethods注意到這個屬性了吧,我們知道,在上圖中,@bean是用來註冊元件到容器之中的,如下圖,我們從容器中連續取倆次pet,取到的是否相等呢,我們知道,當是單例模式時取到的必然相等。那我們回到proxybeanmethods這個屬性,當他為true時,表示註冊到容器中的myconfig這個類是乙個**類,而myconfig這個類可以呼叫tomcatpet()這個方法,容器每次獲取pet物件都會呼叫tomcatpet()這個方法,當容器中的myconfig是乙個**類時,每次呼叫方法之前都會檢查springboot容器中是否有pet物件,如果有就會直接從容器中取出,沒有才呼叫方法建立物件。而當proxybeanmethods這個屬性為false時,表示註冊到容器中的myconfig這個類不是乙個**類,那麼每次呼叫tomcatpet()方法之前不會檢查springboot容器中是否有pet物件,而是直接呼叫方法建立乙個物件,那麼兩個pet物件便不會相同。

@springbootconfiguration

@enableautoconfiguration

@componentscan

("com.atguigu.boot"

)public

class

//3、從容器中獲取元件

pet tom01 = run.

getbean

("tom"

, pet.

class);

pet tom02 = run.

getbean

("tom"

, pet.

class);

system.out.

println

("元件:"

+(tom01 == tom02)

);

因此

配置 類元件之間無依賴關係用lite模式加速容器啟動過程,減少判斷,也就是讓@configuration(proxybeanmethods = false)

配置類元件之間有依賴關係,方法會被呼叫得到之前單例項元件,用full模式,也就是@configuration(proxybeanmethods = true)

python中full函式 Python函式混亂

我正在學習 python.我有乙個函式readwrite filename,list filename的型別為string.list是乙個包含要在檔案中重寫的字串的列表.我有乙個簡單的函式呼叫,如下所示 fname hello.txt readwrite xx fname,datalist 我面臨的...

Springboot的thymeleaf常用屬性

th text對特殊字元進行轉義,作為純文字標籤,等價於內聯方式 welcome to thymeleaf welcome to thymeleaf th utext 對特殊字元不進行轉義,可以顯示出字元的作用,等價於內聯方式 welcome to thymeleaf welcome to thym...

spring boot的Scheduler定時任務

configuration enablescheduling 開啟後台任務 public class scheduler cron second,minute,hour,day of month,month,day s of week scheduled cron 0 每分鐘執行一次 schedul...