1.@PostConstruct注解
? ? 該注解為java的注解
????說明:@PostConstruct該注解被用來修飾一個非靜態(tài)的void()方法。被@PostConstruct修飾的方法會在服務(wù)器架子啊Servlet的時候運(yùn)行,并且只會被服務(wù)器加載一次。@PostConstruct在構(gòu)造函數(shù)之后執(zhí)行,init()方法之前執(zhí)行。
????執(zhí)行順序:Contructor(構(gòu)造方法) -> @Autowired(依賴注入) ->@PostConstruct(注釋的方法)|
????常見用法:將普通的類變量賦值給static靜態(tài)變量??
? ? @Component
????public class TestProperties {
????????private static String testKey;
????????
????????@Value("${app_key}")
????????private String key;
? ? ? ? @PostConstruct
????????public void initTestKey(){
????????????testKey = this.key;
????????}
? ? ? ? public void getKey(){
????????????return testKey;
????????}
????}