Created
June 22, 2012 16:20
-
-
Save dwelch2344/2973807 to your computer and use it in GitHub Desktop.
Autowiring all defined beans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.BeansException; | |
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.ApplicationContextAware; | |
public class DanTest implements ApplicationContextAware{ | |
@Override | |
public void setApplicationContext(ApplicationContext ctx) | |
throws BeansException { | |
AutowireCapableBeanFactory bf = ctx.getAutowireCapableBeanFactory(); | |
for(String name : ctx.getBeanDefinitionNames()){ | |
Object bean = ctx.getBean(name); | |
System.out.println( String.format("Trying to autowire: %s of type %s", name, bean) ); | |
bf.autowireBean(bean); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment