Forked from eeichinger/LazyBeanDefinitionDocumentReader.java
Created
November 10, 2017 11:44
-
-
Save taotao365s/adfc94f77f9a00ae9247cbfd31b5fec2 to your computer and use it in GitHub Desktop.
enforce loading spring beans with default-lazy-init=true
This file contains hidden or 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
| 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; | |
| } | |
| } |
This file contains hidden or 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
| 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