8.0.x - make configurable: allow-bean-definition-overriding / allow-circular-references#15765
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #15765 +/- ##
================================================
+ Coverage 0 49.4717% +49.4717%
- Complexity 0 16685 +16685
================================================
Files 0 1947 +1947
Lines 0 92469 +92469
Branches 0 16150 +16150
================================================
+ Hits 0 45746 +45746
- Misses 0 39619 +39619
- Partials 0 7104 +7104
🚀 New features to boost your workflow:
|
…rable GrailsApp and the unit-test harness GrailsApplicationBuilder hardcoded allowBeanDefinitionOverriding(true) and allowCircularReferences(true), silently overriding any value set through the standard Spring Boot properties spring.main.allow-bean-definition-overriding and spring.main.allow-circular-references. Both now resolve those properties from the configured environment, defaulting to true to preserve Grails' historical behavior (a plain Spring Boot app defaults both to false). Applications can opt into stricter startup semantics via application.yml. - grails-core: GrailsApp.createApplicationContext reads both flags from the configured environment. - grails-testing-support-core: GrailsApplicationBuilder.createMainContext reads the same properties after configuration data is loaded and before refresh. - docs: new section in the Application class configuration guide. - tests: GrailsAppContextOverridingSpec (grails-core) and GrailsApplicationBuilderContextOverridingSpec (grails-databinding). The latter documents that disabling bean definition overriding fails a Grails unit context with BeanDefinitionOverrideException, which is why the default is true.
dbc161b to
0713d3c
Compare
e3b5acf to
9482237
Compare
| // behavior) but can be turned off via the standard spring.main.* properties. These are read | ||
| // after prepareContext so that application.yml (loaded by ConfigDataApplicationContextInitializer) | ||
| // and other property sources are available, and before refresh so the values take effect. | ||
| def environment = context.environment |
There was a problem hiding this comment.
The environment can be initialized prior to the context. As part of the context creation, can't beans be created? This would this make the settings after the fact?
There was a problem hiding this comment.
@jdaugherty Reordered so the environment is initialized and the spring.main.* flags are set before any bean definitions are registered (and before refresh()) — they now apply to the whole context lifecycle instead of after the fact.
|
The environment is indeed initialized during the grails-core/src/main/groovy/grails/boot/GrailsApp.groovy |
…vironment null guard
✅ All tests passed ✅🏷️ Commit: 7e7fd90 Learn more about TestLens at testlens.app. |
Summary
We shouldn't force bad practices and start providing an exit strategy
WARNING: Bean overriding will be deprecated in a future release.
GrailsAppand the unit-test harnessGrailsApplicationBuilderhardcodedallowBeanDefinitionOverriding(true)andallowCircularReferences(true). Thissilently overrode any value an application set through the standard Spring Boot
properties
spring.main.allow-bean-definition-overridingandspring.main.allow-circular-references— so there was no way to turn either off.Both now resolve those properties from the configured environment and default
to
trueto preserve Grails' historical behavior (a plain Spring Boot appdefaults both to
false). Applications can now opt into stricter startupsemantics:
Changes
GrailsApp.createApplicationContext()resolves both flagsfrom the configured environment (defaulting to
true).GrailsApplicationBuilder.createMainContext()resolves the same properties, read after configuration data is loaded and
before
refresh().the Application class configuration guide.
GrailsAppContextOverridingSpec(grails-core) andGrailsApplicationBuilderContextOverridingSpec(grails-databinding).Notes
true. Grails' own bootstrap relies on beandefinition overriding (the harness re-registers infrastructure beans such as
internalConfigurationAnnotationProcessor). The test suite documents thatdisabling overriding makes a Grails context fail fast with
BeanDefinitionOverrideException— which is exactly why the default differsfrom Spring Boot's.
GrailsApplicationBuilderlives ingrails-testing-support-core, but its fullbootstrap requires the servlet API, so its behavioral test lives in
grails-databinding(which has the servlet API on its test classpath andalready exercises the builder).
Verification
./gradlew :grails-core:test :grails-databinding:test :grails-testing-support-core:test :grails-fields:test --rerun-tasks— green.checkstyleMain/codenarcMain+checkstyleTest/codenarcTeston thechanged modules — no violations.