Aware注入 和 Profile註解

2021-10-06 01:15:57 字數 1674 閱讀 8432

自定義元件實現***aware;在建立物件的時候,會呼叫介面規定的方法注入相關元件;

實現 ***xaware;把spring底層一些元件注入到自定義的bean中;

**示例:

@controller

public

class

studentcontroller

implements

}

spring為我們提供的可以根據當前環境,動態的啟用和切換一系列元件的功能;

@profile:指定元件在哪個環境的情況下才能被註冊到容器中,

寫在配置類上,只有是指定的環境的時候,整個配置類裡面的所有配置才能開始生效

沒有標註@profile標識的bean在任何環境下都是載入的;(不指定,任何環境下都能註冊這個元件)

**示例:

@propertysource

("classpath:/dbconfig.properties"

)@configuration

public

class

mainconfigofprofile

implements

embeddedvalueresolveraware")

private string user;

private strin**alueresolver valueresolver;

private string driverclass;

@bean

public yellow yellow()

@profile

("test"

)@bean

("testdatasource"

)public datasource datasourcetest

(@value

("$"

)string pwd)

throws exception

@profile

("dev"

)@bean

("devdatasource"

)public datasource datasourcedev

(@value

("$"

)string pwd)

throws exception

@profile

("prod"

)@bean

("proddatasource"

)public datasource datasourceprod

(@value

("$"

)string pwd)

throws exception

@override

public

void

setembeddedvalueresolver

(strin**alueresolver resolver)")

;}}

public

class

ioctest_profile

getbean

(yellow.

class);

system.out.

println

(bean)

;close()

;}}

Linux bashrc和profile的學習

linux的shell有兩種方式 1.login shell 例如開啟乙個terminal,然後輸入一些命令,退出時shell結束 2.non login shell 例如執行乙個shell指令碼,當指令碼執行完成,shell結束 bashrc用於儲存non login模式環境設定資訊,profil...

linux bashrc和profile的區別

bashrc與profile的區別 要搞清bashrc與profile的區別,首先要弄明白什麼是互動式shell和非互動式shell,什麼是login shell 和non login shell。互動式模式就是shell等待你的輸入,並且執行你提交的命令。這種模式被稱作互動式是因為shell與使用...

Linux中 bashrc和profile的區別

之前安裝qt 4.7.2,由於習慣了在命令列下編譯原始檔,我在網上搜了一下關於qt環境變數的配置方法,配置很簡單,在 etc profile檔案裡新增下面幾行語句 export qtdir opt qtsdk 2010.05 qt 這個路徑根據自己安裝的位置進行配置 export ld librar...