You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "codeconsole (via GitHub)" <gi...@apache.org> on 2026/07/13 14:57:18 UTC
[PR] Honor EnvironmentAware application classes before early plugin registration [grails-core]
codeconsole opened a new pull request, #15979:
URL: https://github.com/apache/grails-core/pull/15979
### Problem
#15934 retimed plugin `doWithSpring` to run before Spring Boot auto-configuration — and therefore before any bean is created. An application class using the long-documented externalized-configuration pattern:
```groovy
class Application extends GrailsAutoConfiguration implements EnvironmentAware {
void setEnvironment(Environment environment) {
// fetch secrets / discover endpoints, addFirst a property source
}
}
```
previously had `setEnvironment` invoked (when the application configuration bean was instantiated) *before* plugin bean registration ran. After the retiming, plugins that resolve settings inside `doWithSpring` read configuration the application has not customized yet. The GORM plugins resolve their connection URLs there — e.g. `MongodbGrailsPlugin.doWithSpring()` builds `MongoDbDataStoreSpringInitializer` from `config` at definition time — so an app that injects its production MongoDB URL from a secret manager in `setEnvironment` silently boots against the static yaml default (`localhost`) instead. Beans that read the `Environment` at creation time (Redis, Elasticsearch, `@Value`) are unaffected, which makes the failure look like a Mongo-specific mystery. This is a real-world regression observed in production on the re-staged 8.0.0-M3.
### Fix
Replay the contract at the start of `GrailsEarlyPluginRegistrationPostProcessor`: for each stashed application source class that is a `GrailsAutoConfiguration`/`GrailsApplicationClass` and implements `EnvironmentAware`, invoke `setEnvironment` on a detached instance — the same approach the phase already uses for artefact scanning (`scanApplicationSource`) — before plugin loading, the `PropertySourcesConfig` snapshot, and the `doWithSpring` drain.
The real application bean still receives the standard `EnvironmentAware` callback when Spring creates it later, so implementations must be idempotent: contribute a *named* property source (re-adding a source with the same name replaces the earlier one) rather than accumulate state. This is documented on the new method and asserted in the spec (`INVOCATIONS == 2`, no duplicated source).
### Testing
New test in `EarlyPluginRegistrationOrderingSpec`: a plugin that reads config in `doWithSpring` (as the GORM plugins do) observes the value contributed by the application's `setEnvironment`, not the default; the double-callback semantics are pinned. Full `:grails-core:test` and checkstyle pass.
Happy to add an upgrade-notes entry in grails-doc ("`setEnvironment` on `EnvironmentAware` application classes now runs twice; keep it idempotent") if wanted.
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor EnvironmentAware application classes before early plugin registration [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15979:
URL: https://github.com/apache/grails-core/pull/15979#issuecomment-4960602142
## ✅ All tests passed ✅
🏷️ Commit: a5a0b5ffa322c585e487d11a0fabe721c7c304b6
▶️ Tests: 55170 executed
⚪️ Checks: 59/59 completed
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Honor EnvironmentAware application classes before early plugin registration [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole closed pull request #15979: Honor EnvironmentAware application classes before early plugin registration
URL: https://github.com/apache/grails-core/pull/15979
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org