一般會基本使用
知曉 full模式與lite模式
------- 最佳實戰主要有如下兩點
• 配置 類元件之間無依賴關係用lite模式加速容器啟動過程,減少判斷
• 配置類元件之間有依賴關係,方法會被呼叫得到之前單例項元件,用full模式
1、配置類裡面使用@bean標註在方法上給容器註冊元件,預設也是單例項的
2、配置類本身也是元件
3、proxybeanmethods:**bean的方法
@import()@configuration
(proxybeanmethods =
false
)//告訴springboot這是乙個配置類 == 配置檔案
public
class
myconfig
@bean
("tom"
)public pet tomcatpet()
}
給容器中自動建立出這兩個型別的元件、預設元件的名字就是全類名
條件裝配:滿足conditional指定的條件,則進行元件注入@import()
@configuration
(proxybeanmethods =
false
)//告訴springboot這是乙個配置類 == 配置檔案
public
class
myconfig
//當元件中含有tom這個元件時這個類元件才生效,加在方法上就是這個方法元件就會註冊
@conditionalo****singbean
(name =
"tom"
)public
class
myconfig
配置繫結
配置檔案中比如寫了
mycar.brand=bbb
mycar.price=1000
/**
* 只有在容器中的元件,才會擁有springboot提供的強大功能
*/@component
@configurationproperties
(prefix =
"mycar"
)public
class
car......
Configuration 配置物件
hibernate.cfg.xml通常使用xml配置檔案,可以配置內容更豐富。hibernate.properties用於配置key value 形式的內容,key不能重複的。配置有很多的侷限性。一般不用。可以進入hibernate distribution 3.6.10.final project...
Configuration註解 Bean註解
package com.test.spring.support.configuration configuration public class testconfiguration xmlns xmlns xsi xmlns context xmlns jdbc xmlns jee xmlns tx...
Sping中的 Configuration註解
使用要求 configuration不可以是final型別。configuration不可以是匿名類。巢狀的configuration必須是靜態類。bean類 public class testbean public string tostring public void start public ...