springboot中獲取bean物件

2021-10-19 08:23:09 字數 2200 閱讀 2231

@component

public

final

class

springutils

implements

beanfactorypostprocessor

@override

public

void

throws bean***ception

/** * 獲取物件

** @param name

* @return object 乙個以所給名字註冊的bean的例項

* @throws org.springframework.beans.bean***ception**/

@suppresswarnings

("unchecked"

)public

static

t getbean

(string name)

throws bean***ception

/** * 獲取型別為requiredtype的物件

** @param clz

* @return

* @throws org.springframework.beans.bean***ception**/

public

static

t getbean

(class

clz)

throws bean***ception

/** * 如果beanfactory包含乙個與所給名稱匹配的bean定義,則返回true

** @param name

* @return boolean

*/public

static

boolean

containsbean

(string name)

/** * 判斷以給定名字註冊的bean定義是乙個singleton還是乙個prototype。 如果與給定名字相應的bean定義沒有被找到,將會丟擲乙個異常(nosuchbeandefinitionexception)

** @param name

* @return boolean

* @throws org.springframework.beans.factory.nosuchbeandefinitionexception**/

public

static

boolean

issingleton

(string name)

throws nosuchbeandefinitionexception

/** * @param name

* @return class 註冊物件的型別

* @throws org.springframework.beans.factory.nosuchbeandefinitionexception**/

public

static class<

?>

gettype

(string name)

throws nosuchbeandefinitionexception

/** * 如果給定的bean名字在bean定義中有別名,則返回這些別名

** @param name

* @return

* @throws org.springframework.beans.factory.nosuchbeandefinitionexception**/

public

static string[

]getaliases

(string name)

throws nosuchbeandefinitionexception

/** * 獲取aop**物件

** @param invoker

* @return

*/@suppresswarnings

("unchecked"

)public

static

t getaopproxy

(t invoker)

/** * 獲取當前的環境配置,無配置返回null

** @return 當前的環境配置

*/public

static string[

]getactiveprofiles()

}

SpringBoot獲取properties配置

前言 在專案中,很多時候需要把配置寫在properties裡,部署的時候也需要切換不同的環境來選擇正確的配置的引數,也有時候需要將mq redis等第三方配置新建乙個properties檔案在專案中引用。1.因為是spring的環境,當然首先需要搭建好spring環境。package com.exa...

SpringBoot獲取properties配置

擼了今年阿里 網易和美團的面試,我有乙個重要發現.前言 在專案中,很多時候需要把配置寫在properties裡,部署的時候也需要切換不同的環境來選擇正確的配置的引數,也有時候需要將mq redis等第三方配置新建乙個properties檔案在專案中引用。1.因為是spring的環境,當然首先需要搭建...

SpringBoot獲取資料

配置檔案中資料 name abc 物件persion name lele age 29 物件行內寫法 persion2 陣列address beijing shanghai 陣列行內寫法 address2 beijing,shanghai msg1 hello n world 不會識別轉譯字元,原樣...