codeconsole commented on code in PR #15939:
URL: https://github.com/apache/grails-core/pull/15939#discussion_r3552825583
##########
grails-core/src/main/groovy/org/grails/plugins/DefaultGrailsPlugin.java:
##########
@@ -391,13 +391,17 @@ public void
doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
b.setVariable("resolver", getResolver());
if (plugin instanceof Plugin) {
- Closure c = ((Plugin) plugin).doWithSpring();
+ Plugin pluginObject = (Plugin) plugin;
+ BeanBuilder bb = new BeanBuilder(getParentCtx(), springConfig,
grailsApplication.getClassLoader());
+ bb.setBinding(b);
+ // Legacy closure-returning hook: doWithSpring() returns a
bean-defining closure
+ Closure c = pluginObject.doWithSpring();
if (c != null) {
- BeanBuilder bb = new BeanBuilder(getParentCtx(), springConfig,
grailsApplication.getClassLoader());
- bb.setBinding(b);
c.setDelegate(bb);
bb.invokeMethod("beans", new Object[]{c});
}
+ // Method-based hook: doWithSpring(BeanBuilder) registers beans
directly against the builder
+ pluginObject.doWithSpring(bb);
Review Comment:
Switched to a hard error as you prefer. A plugin that defines both
`doWithSpring()` and `doWithSpring(BeanBuilder)` now throws a `PluginException`
and fails to load, rather than running both with a warning:
```java
Closure c = pluginObject.doWithSpring();
if (c != null && isDoWithSpringMethodOverridden(pluginObject)) {
throw new PluginException("Plugin [" + this + "] defines both the
closure-returning doWithSpring() " +
"and the doWithSpring(BeanBuilder) method. Define only one
Spring configuration hook.");
}
```
`PluginDoWithSpringMethodSpec` now asserts the exception (and its message
identifies both conflicting hooks) instead of asserting both beans register.
Docs updated to state that defining both fails plugin load. Pushed in 029aa5e.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]