I coded an example from the Just Spring book which implements a BeanPostProcessor. The example uses an xml configuration file which declares one bean and the BeanPostProcessing bean. My understanding is the BeanPostProcessing bean will be detected automatically by Spring and applied to all the other beans in the container. This appears to work as advertised with one slight catch.. I test the bean with the following code:
public static void main( String[] args) {
GenericXmlApplicationContext ctx = null;
// Create container with xml file
ctx = new GenericXmlApplicationContext("classpath:bean-post-proc-config.xml");
// ctx.refresh();
// Obtain a Trade object from the container
Trade trade = (Trade)ctx.getBean("trade");
.....
Where Trade is the one bean declared in the xml file. The catch is that when I uncomment out the ctx.refresh() I get an error about calling refresh() twice:
Exception in thread "main" java.lang.IllegalStateException: GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once
at org.springframework.context.support.GenericApplica tionContext.refreshBeanFactory(GenericApplicationC ontext.java:242)
at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:467)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:397)
at com.justspring.ch3.beanpostproc.BeanPostProcExampl e.main(BeanPostProcExample.java:17)
Can someone expain this error?


Reply With Quote
