@@ -68,15 +68,10 @@ class GrailsApplicationPostProcessor implements BeanDefinitionRegistryPostProces
6868
6969 GrailsApplicationPostProcessor (GrailsApplicationLifeCycle lifeCycle , ApplicationContext applicationContext , Class ...classes ) {
7070 this . lifeCycle = lifeCycle
71- if (lifeCycle instanceof GrailsApplicationClass ) {
72- this . applicationClass = (GrailsApplicationClass )lifeCycle
73- }
74- else {
75- this . applicationClass = null
76- }
77- this . classes = classes != null ? classes : [] as Class []
78- grailsApplication = applicationClass != null ? new DefaultGrailsApplication (applicationClass) : new DefaultGrailsApplication ()
79- pluginManager = new DefaultGrailsPluginManager (grailsApplication)
71+ this . applicationClass = lifeCycle instanceof GrailsApplicationClass ? (GrailsApplicationClass ) lifeCycle : null
72+ this . classes = classes ?: [] as Class []
73+ this . grailsApplication = applicationClass ? new DefaultGrailsApplication (applicationClass) : new DefaultGrailsApplication ()
74+ this . pluginManager = applicationContext?. getBeanNamesForType(GrailsPluginManager ) ? applicationContext. getBean(GrailsPluginManager ) : new DefaultGrailsPluginManager (grailsApplication)
8075 if (applicationContext != null ) {
8176 setApplicationContext(applicationContext)
8277 }
@@ -290,30 +285,22 @@ class GrailsApplicationPostProcessor implements BeanDefinitionRegistryPostProces
290285 }
291286 }
292287
293- @SuppressWarnings (" GrMethodMayBeStatic" )
294288 private void loadPluginConfigurationsToMicronautContext (ConfigurableApplicationContext applicationContext ) {
295- String [] beanNames = applicationContext . getBeanNamesForType( GrailsPluginManager )
296- if (beanNames . length == 0 ) {
297- // do not continue if PluginManager is not available
289+ ConfigurableApplicationContext parentApplicationContext = ( ConfigurableApplicationContext ) applicationContext . parent
290+ if (! parentApplicationContext ) {
291+ // No Micronaut parent context, return early
298292 return
299293 }
300-
301- GrailsPluginManager pluginManager = applicationContext. getBean(GrailsPluginManager )
302- ConfigurableApplicationContext parentApplicationContext = (ConfigurableApplicationContext ) applicationContext. parent
303294 ConfigurableEnvironment parentContextEnv = parentApplicationContext. getEnvironment()
304295 if (parentContextEnv instanceof MicronautEnvironment ) {
305- if (log. isDebugEnabled()) {
306- log. debug(" Loading configurations from the plugins to the parent Micronaut context" )
307- }
296+ log. debug(' Loading configurations from the plugins to the parent Micronaut context' )
308297 final io.micronaut.context.env.Environment micronautEnv = ((io.micronaut.context.env.Environment ) parentContextEnv. getEnvironment())
309298 final GrailsPlugin [] plugins = pluginManager. allPlugins
310299 Integer priority = AbstractPropertySourceLoader . DEFAULT_POSITION
311300 Arrays . stream(plugins)
312301 .filter({ GrailsPlugin plugin -> plugin. propertySource != null })
313302 .forEach({ GrailsPlugin plugin ->
314- if (log. isDebugEnabled()) {
315- log. debug(" Loading configurations from {} plugin to the parent Micronaut context" , plugin. name)
316- }
303+ log. debug(' Loading configurations from {} plugin to the parent Micronaut context' , plugin. name)
317304 micronautEnv. addPropertySource(PropertySource . of(" grails.plugins.$plugin . name " , (Map ) plugin. propertySource. source, -- priority))
318305 })
319306 micronautEnv. refresh()
0 commit comments