[英]Spring Configuration Init Method
How can I tell Spring to run that init method?我如何告诉 Spring 运行该 init 方法? I need to get the Proxied Async class and do some initialization with it.
我需要获取 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来做到这一点
Use the @PostConstruct
annotation along with:使用
@PostConstruct
注释以及:
<context:annotation-config />
or <context:annotation-config />
或<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
See here for details.有关详细信息,请参见此处。 This is a Java EE annotation, so may not be appropriate in your environment.
这是一个 Java EE 注释,因此可能不适合您的环境。
BeanPostProcessor
BeanPostProcessor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.