[英]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.