Reputation: 21981
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 "";
}
}
Upvotes: 10
Views: 20134
Reputation: 160191
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.
Upvotes: 4
Reputation: 597076
BeanPostProcessor
Upvotes: 0