Spring Configuration Init Method

DD. picture DD. · Jan 4, 2012 · Viewed 15.2k times · Source

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 "";
 }

}

Answer

JustinKSU picture JustinKSU · Jan 4, 2012

You could use @PostConstruct