Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eeichinger/1979033 to your computer and use it in GitHub Desktop.
Save eeichinger/1979033 to your computer and use it in GitHub Desktop.
enforce loading spring beans with default-lazy-init=true
public class LazyBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocumentReader {
@Override
protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
root.setAttribute("default-lazy-init", "true");
BeanDefinitionParserDelegate delegate = super.createHelper(readerContext, root, parentDelegate);
return delegate;
}
}
public class LazyClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {
public LazyClassPathXmlApplicationContext(String path) throws BeansException {
super(path);
}
@Override
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
super.initBeanDefinitionReader(reader);
reader.setDocumentReaderClass(LazyBeanDefinitionDocumentReader.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment