Search code examples
javaspringspring-3

Spring Configuration Init Method


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

}

Solution

  • You could use @PostConstruct to do this