[英]Spring Configuration Init Method
我如何告訴 Spring 運行該 init 方法? 我需要獲取 Proxied Async 類並用它進行一些初始化。
@Configuration
@EnableAsync
public class Config {
@Bean
public AsyncBean asyncProxyBean(){
return new AsyncBean();
}
public void init(){
doStuffWithProxy(asyncProxyBean());
}
@Bean
public String thisIsHack(){ //this runs the init code but bean is a bit hacky
doStuffWithProxy(asyncProxyBean());
return "";
}
}
你可以使用@PostConstruct來做到這一點
使用@PostConstruct
注釋以及:
<context:annotation-config />
或<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
有關詳細信息,請參見此處。 這是一個 Java EE 注釋,因此可能不適合您的環境。
BeanPostProcessor
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.