Skip to content

Commit aae90ea

Browse files
committed
GRAILS-5763 - manually apply all registered factory post processors after each plugin invokes its change handler.
The motivating issue was that the property override mechanism failed when a bean was reloaded by a plugin.
1 parent 1c76a0e commit aae90ea

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/java/org/codehaus/groovy/grails/plugins/DefaultGrailsPlugin.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
import org.codehaus.groovy.grails.documentation.DocumentationContext;
4040
import org.springframework.beans.BeanWrapper;
4141
import org.springframework.beans.BeanWrapperImpl;
42+
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
43+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
4244
import org.springframework.context.ApplicationContext;
45+
import org.springframework.context.support.GenericApplicationContext;
4346
import org.springframework.core.io.Resource;
4447
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
4548
import org.springframework.core.type.filter.TypeFilter;
@@ -1043,6 +1046,16 @@ private void callEvent(Closure closureHook, Map event) {
10431046
private void invokeOnChangeListener(Map event) {
10441047
onChangeListener.setDelegate(this);
10451048
onChangeListener.call(new Object[]{event});
1049+
1050+
// Apply any factory post processors in case the change listener has changed any
1051+
// bean definitions (GRAILS-5763)
1052+
if (applicationContext instanceof GenericApplicationContext) {
1053+
GenericApplicationContext ctx = (GenericApplicationContext) applicationContext;
1054+
ConfigurableListableBeanFactory beanFactory = ctx.getBeanFactory();
1055+
for (BeanFactoryPostProcessor postProcessor : ctx.getBeanFactoryPostProcessors()) {
1056+
postProcessor.postProcessBeanFactory(beanFactory);
1057+
}
1058+
}
10461059
}
10471060

10481061
public void doArtefactConfiguration() {
@@ -1090,4 +1103,4 @@ public Collection<? extends TypeFilter> getTypeFilters() {
10901103
return this.typeFilters;
10911104
}
10921105

1093-
}
1106+
}

src/test/org/codehaus/groovy/grails/plugins/CoreGrailsPluginTests.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,16 @@ class CoreGrailsPluginTests extends AbstractGrailsMockTests {
8585

8686
assertEquals(1, appCtx.getBean('someTransactionalService').i)
8787
assertEquals(2, appCtx.getBean('nonTransactionalService').i)
88+
89+
// test that the overrides are applied on a reload - GRAILS-5763
90+
plugin.manager = [informObservers: { String pluginName, Map event -> }] as GrailsPluginManager
91+
plugin.applicationContext = appCtx
92+
93+
["SomeTransactionalService", "NonTransactionalService"].each {
94+
plugin.notifyOfEvent(GrailsPlugin.EVENT_ON_CHANGE, gcl.loadClass(it))
95+
}
96+
97+
assertEquals(1, appCtx.getBean('someTransactionalService').i)
98+
assertEquals(2, appCtx.getBean('nonTransactionalService').i)
8899
}
89100
}

0 commit comments

Comments
 (0)