Skip to content

Instantly share code, notes, and snippets.

@dovidkopel
Last active March 17, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dovidkopel/28c964336952c6fa19d1 to your computer and use it in GitHub Desktop.
Save dovidkopel/28c964336952c6fa19d1 to your computer and use it in GitHub Desktop.
import org.springframework.beans.factory.BeanFactory;
public enum BeanAccessor {
INSTANCE;
private static BeanFactory beanFactory;
public static void setBeanFactory(BeanFactory _beanFactory) {
beanFactory = _beanFactory;
}
public static <T> T getBean(Class<T> clazz) {
return beanFactory.getBean(clazz);
}
}
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class BeanFactoryConfiguration {
@Autowired
public void setBeanAccessor(BeanFactory beanFactory) {
BeanAccessor.setBeanFactory(beanFactory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment