Filter out duplicate ApplicationContextAwareProcessors in parent/child

contexts scenarios

AbstractApplicationContextFactory, when configuring a child context,
copies all of the BeanPostProcessors from the parent to the child.
Normally this is a good thing.  However, in the case of teh
ApplicationContextAwareProcessor, the child context ends up with two
instances, one for the parent context and one for the child context.
This brings two issues to light:
  1. Unknown which context is being injected - On beans implementing
ApplicationContextAware, it can't be determined which context (the
parent or the child) will be injected since both BPPs will be called in
an indeterimant order.
 2. Errors occur with ApplicationObjectSupport - If the child context
contains a bean that extends ApplicationObjectSupport, when the second
ApplicationContextAwareProcessor is called, the bean will throw an
exception since it is only allowed to be initialized with one
application context.

This fix adds additional logic to remove the
ApplicationContextAwareProcessor from the parent context before adding
all the BPPs to the child.

This fix addresses BATCH-2319.
This commit is contained in:
Michael Minella
2014-11-04 16:12:50 -06:00
parent a066647149
commit 7683700662
2 changed files with 59 additions and 17 deletions

View File

@@ -15,7 +15,12 @@
*/
package org.springframework.batch.core.configuration.annotation;
import static org.junit.Assert.assertEquals;
import javax.annotation.PostConstruct;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
@@ -36,10 +41,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import static org.junit.Assert.assertEquals;
import org.springframework.context.support.ApplicationObjectSupport;
/**
* @author Dave Syer
@@ -114,6 +116,11 @@ public class JobLoaderConfigurationTests {
@Configuration
public static class TestConfiguration {
@Bean
public ApplicationObjectSupport fakeApplicationObjectSupport() {
return new ApplicationObjectSupport() {};
}
@Autowired
private JobBuilderFactory jobs;