2020import org .apache .commons .logging .Log ;
2121import org .apache .commons .logging .LogFactory ;
2222import org .codehaus .groovy .grails .commons .*;
23+ import org .codehaus .groovy .grails .exceptions .GrailsConfigurationException ;
2324import org .codehaus .groovy .grails .plugins .DefaultGrailsPluginManager ;
2425import org .codehaus .groovy .grails .plugins .GrailsPluginManager ;
2526import org .codehaus .groovy .grails .plugins .PluginManagerHolder ;
26- import org .codehaus .groovy .grails .exceptions .GrailsConfigurationException ;
2727import org .springframework .aop .framework .ProxyFactoryBean ;
2828import org .springframework .aop .target .HotSwappableTargetSource ;
29+ import org .springframework .beans .BeansException ;
2930import org .springframework .beans .factory .config .BeanDefinition ;
31+ import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
3032import org .springframework .beans .factory .config .MethodInvokingFactoryBean ;
3133import org .springframework .beans .factory .config .RuntimeBeanReference ;
3234import org .springframework .beans .factory .support .ManagedList ;
3335import org .springframework .beans .factory .xml .XmlBeanFactory ;
34- import org .springframework .beans .BeansException ;
3536import org .springframework .context .ApplicationContext ;
3637import org .springframework .context .ApplicationContextAware ;
38+ import org .springframework .context .ConfigurableApplicationContext ;
3739import org .springframework .core .io .Resource ;
3840import org .springframework .mock .web .MockServletContext ;
3941import org .springframework .transaction .interceptor .TransactionProxyFactoryBean ;
4042import org .springframework .util .Assert ;
43+ import org .springframework .util .ClassUtils ;
4144import org .springframework .web .context .WebApplicationContext ;
4245
4346import javax .servlet .ServletContext ;
4447import java .io .IOException ;
45- import java .util .*;
48+ import java .util .Collection ;
49+ import java .util .Iterator ;
50+ import java .util .List ;
51+ import java .util .Properties ;
4652
4753/**
4854* A class that handles the runtime configuration of the Grails ApplicationContext
@@ -76,8 +82,9 @@ public class GrailsRuntimeConfigurator implements ApplicationContextAware {
7682 private ApplicationContext parent ;
7783 private boolean parentDataSource ;
7884 private GrailsPluginManager pluginManager ;
85+ private boolean loadExternalPersistenceConfig ;
7986
80- public GrailsRuntimeConfigurator (GrailsApplication application ) {
87+ public GrailsRuntimeConfigurator (GrailsApplication application ) {
8188 this (application , null );
8289 }
8390
@@ -332,7 +339,8 @@ private void doPostResourceConfiguration(RuntimeSpringConfiguration springConfig
332339 if (springResources .exists ()) {
333340 LOG .debug ("[RuntimeConfiguration] Configuring additional beans from " +springResources .getURL ());
334341 XmlBeanFactory xmlBf = new XmlBeanFactory (springResources );
335- xmlBf .setBeanClassLoader (Thread .currentThread ().getContextClassLoader ());
342+ ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
343+ xmlBf .setBeanClassLoader (classLoader );
336344 String [] beanNames = xmlBf .getBeanDefinitionNames ();
337345 LOG .debug ("[RuntimeConfiguration] Found [" +beanNames .length +"] beans to configure" );
338346 for (int k = 0 ; k < beanNames .length ; k ++) {
@@ -345,8 +353,15 @@ private void doPostResourceConfiguration(RuntimeSpringConfiguration springConfig
345353 BeanDefinition bd = xmlBf .getBeanDefinition (beanNames [k ]);
346354
347355 springConfig .addBeanDefinition (beanNames [k ], bd );
356+ Class beanClass = ClassUtils .forName (bd .getBeanClassName (), classLoader );
357+ if (BeanFactoryPostProcessor .class .isAssignableFrom (beanClass )) {
358+ ((ConfigurableApplicationContext )springConfig .getUnrefreshedApplicationContext ())
359+ .addBeanFactoryPostProcessor ((BeanFactoryPostProcessor )xmlBf .getBean (beanNames [k ]));
360+ }
348361 }
349362
363+
364+
350365 }
351366 else if (LOG .isDebugEnabled ()) {
352367 LOG .debug ("[RuntimeConfiguration] " + GrailsRuntimeConfigurator .SPRING_RESOURCES_XML + " not found. Skipping configuration." );
@@ -357,12 +372,15 @@ else if(LOG.isDebugEnabled()) {
357372 bb .setSpringConfig (springConfig );
358373 bb .loadBeans (groovySpringResources );
359374 }
375+
376+
360377 } catch (Exception ex ) {
361378 LOG .warn ("[RuntimeConfiguration] Unable to perform post initialization config: " + SPRING_RESOURCES_XML , ex );
362379 }
363380 }
364381
365382 public void setLoadExternalPersistenceConfig (boolean b ) {
383+ this .loadExternalPersistenceConfig = b ;
366384 }
367385
368386 public void setPluginManager (GrailsPluginManager manager ) {
0 commit comments