Spring Configuration Init Method
16,188
Solution 1
You could use @PostConstruct to do this
Solution 2
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.
Author by
DD.
Updated on July 17, 2022Comments
-
DD. almost 2 years
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 ""; } }