How can I tell Spring to run that init method? I need to get the Proxied Async class and do some initialization with it.
@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:
<context:annotation-config />
or <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.
BeanPostProcessor
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.