Repository navigation
Start every context of a GrailsAppBuilder hierarchy with a GrailsApp - #16462
Conversation
GrailsAppBuilder only swapped in a GrailsApp for the builder it was constructed as; Spring Boot's child(), parent() and sibling() still produced plain SpringApplicationBuilders, so a hierarchy lost the Grails startup defaults and the parent of a Grails web child failed to start with "No bean named 'classLoader' available", because the plain parent, launched by a GrailsApp, ran the plugin lifecycle too. The builder now owns the hierarchy itself and overrides every Boot fluent method with a covariant return, so a chain stays in Grails terms and every context of a hierarchy is started by a GrailsApp. GrailsApp records the members of a hierarchy and runs the plugin lifecycle in the one whose sources include the Grails application class, logging when a member leaves it out; a standalone GrailsApp keeps running the lifecycle whatever its sources are. The development-mode watch starts only in the context that owns the plugin manager. Covered by GrailsAppBuilderSpec, GrailsAppContextHierarchySpec, a hierarchy feature of DevelopmentModeWatchSpec and two example applications: a shared Spring parent with a Grails web child, and a command-line program with a non-web Grails parent and a Spring child. Documented in a short section of "Executing the Application Class".
Builds on the 8.0.x fix that starts every context of a GrailsAppBuilder hierarchy with a GrailsApp (#16462), and settles what a hierarchy means for the Grails lifecycle, which keeps JVM-wide state: Holders, the initializing flag, the shutdown operations and the development watch. Exactly one context of a hierarchy is the Grails application. A context whose parent chain already holds a grailsApplication refuses to start as a second one. GrailsApplicationPostProcessor registers grailsApplication and pluginManager locally in every context and lends them to the parent, and takes the loan back in DisposableBean.destroy(), which Spring runs on a normal close and on a failed refresh alike, so a parent that outlives its Grails child holds nothing of it and another Grails child can start beneath it; a parent bean that injected the lent singletons is destroyed with them and recreated against the next loan, and the docs point parent beans at ObjectProvider instead. The contextHierarchyMember flag the builder sets becomes a public GrailsApp property, so a hierarchy assembled by hand can set it. No running address is reported for a context without a web server. Documented in a new "Building the Application" page and the what's new section, which replace the short section the fix added to "Executing the Application Class", and exercised by the second-application refusal and loan-return specs and by the web example's sibling-refusal spec.
|
@matrei this is the 8.0.x half of #16456, split out as you suggested in your review there: Could you review this one first? The specs here assert only what 8.0.x does: the parent holds the child's |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16462 +/- ##
==================================================
+ Coverage 58.9311% 58.9462% +0.0150%
- Complexity 24441 24502 +61
==================================================
Files 2174 2174
Lines 107366 107476 +110
Branches 19557 19562 +5
==================================================
+ Hits 63272 63353 +81
- Misses 35231 35261 +30
+ Partials 8863 8862 -1
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: b4b09c4 Learn more about TestLens at testlens.app/docs. |
|
This was split off the other PR that is already reviewed. Going to merge this and we can iterate if we need to. |
Description
Bug fix split out of #16456, as discussed in its review.
GrailsAppBuilderonly swapped in aGrailsAppfor the builder it was constructed as. Spring Boot'schild(),parent()andsibling()still produced plainSpringApplicationBuilders, so a hierarchy lost the Grails startup defaults, and because the plain parent was launched by aGrailsAppit ran the plugin lifecycle too: on 8.0.x,new GrailsAppBuilder(Shared).child(Application).run(args)fails withNo bean named 'classLoader' availablewhile creatinggroovyPagesTemplateEnginein the parent.The builder now owns the hierarchy itself and overrides every Boot fluent method with a covariant
GrailsAppBuilderreturn, so every context of a hierarchy is started by aGrailsApp.GrailsApprecords the members of a hierarchy (a package-scoped flag the builder sets) and runs the plugin lifecycle in the one whose sources include the Grails application class, logging atINFOwhen a member leaves it out. A standaloneGrailsAppkeeps running the lifecycle whatever its sources are. The development-mode watch starts only in the context that owns the plugin manager.Covered by
GrailsAppBuilderSpec,GrailsAppContextHierarchySpec, a hierarchy feature ofDevelopmentModeWatchSpec, and two example applications: a shared Spring parent with a Grails web child, and a command-line program with a non-web Grails parent and a Spring child. Documented in a short section of "Executing the Application Class".What stays in #16456 for 8.1: registering
grailsApplicationandpluginManagerlocally in every context and withdrawing them from the parent when the Grails child closes or fails to start, the refusal of a second Grails application in one hierarchy, the run-status line for contexts without a web server, the publiccontextHierarchyMemberproperty, and the full "Building the Application" page.Contributor Checklist
Issue and Scope
8.0.x, with the feature parts left on8.1.x.Code Quality
:grails-core:codeStyleis clean).Licensing and Attribution