Hi everyone,
I need to read the bean definitions of a set of Spring configuration files without instantiating the beans.
The purpose of this is to go through the bean definitions and detect which beans contain properties whose values came from a placeholder.
My initial attempt was this, which loads the context in the first line:
However, I can't initialize the context since there are beans that have a constructor argument that require having a valid value upon instantiation, and the placeholder's format makes that validation fail.Code:AbstractRefreshableApplicationContext ctx = new FileSystemXmlApplicationContext("c:\\tmp\\ctx.xml"); DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
My second attempt was this, which lazily loads the context:
But that code causes this exception:Code:AbstractRefreshableApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"ctx.xml"}, false); DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefres hableApplicationContext.getBeanFactory(AbstractRef reshableApplicationContext.java:171)
Is there a way to read the context configuration without the initialization of the context?
Thanks a lot in advance,
Hernan


Reply With Quote
