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/10/03 20:22:45 UTC
[PR] Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
codeconsole opened a new pull request, #16496:
URL: https://github.com/apache/grails-core/pull/16496
## Problem
`grails-data-mongodb-spring-boot` registered `MongoDbGormAutoConfiguration` in `META-INF/services/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports`. Spring Boot reads `META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports`, so the auto-configuration was never applied: a Spring Boot application with the module on its classpath got no `MongoDatastore` and none of its GORM data services.
The module's own example, `grails-test-examples/mongodb/springboot`, does not start:
```
Field bookService in example.BookController required a bean of type 'example.BookService' that could not be found.
```
Nothing caught it. The module's tests import the auto-configuration explicitly, and the example's test builds a `MongoDatastore` by hand instead of starting the application. Every other module in the repository puts the file under `META-INF/spring/`.
Grails applications are not affected. They get GORM for MongoDB from the `mongodb` Grails plugin, and do not depend on this module.
## Change
The file moves to `META-INF/spring/`. With it there, the example application starts and serves its books.
## Tests
`MongoDbGormAutoConfigurationDiscoverySpec` checks that Spring Boot's `ImportCandidates` lists `MongoDbGormAutoConfiguration`, and starts a `@SpringBootApplication` that imports nothing against a MongoDB container, then saves and counts an entity through GORM. Both features fail with the file in its old place, the second with `No qualifying bean of type 'org.grails.datastore.mapping.mongo.MongoDatastore' available`. The module's tests and the `mongodb/springboot` example's test pass.
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on code in PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#discussion_r4174999691
##########
grails-data-mongodb/boot-plugin/src/test/groovy/org/grails/datastore/gorm/mongodb/boot/autoconfigure/discovered/MongoDbGormAutoConfigurationDiscoverySpec.groovy:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.datastore.gorm.mongodb.boot.autoconfigure.discovered
+
+import grails.gorm.annotation.Entity
+import grails.gorm.transactions.Transactional
+
+import org.springframework.boot.WebApplicationType
+import org.springframework.boot.autoconfigure.AutoConfiguration
+import org.springframework.boot.autoconfigure.SpringBootApplication
+import org.springframework.boot.builder.SpringApplicationBuilder
+import org.springframework.boot.context.annotation.ImportCandidates
+import org.springframework.context.ConfigurableApplicationContext
+import org.springframework.stereotype.Service
+
+import org.apache.grails.testing.mongo.AbstractMongoGrailsExtension
+import org.apache.grails.testing.mongo.AutoStartedMongoSpec
+import org.grails.datastore.gorm.mongodb.boot.autoconfigure.MongoDbGormAutoConfiguration
+import org.grails.datastore.mapping.mongo.MongoDatastore
+
+/**
+ * Spring Boot finds an auto-configuration by reading
+ * {@code META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports}. Nothing here imports
+ * {@link MongoDbGormAutoConfiguration}, so the application gets GORM only if that file names it.
+ */
+class MongoDbGormAutoConfigurationDiscoverySpec extends AutoStartedMongoSpec {
+
+ @Override
+ boolean shouldInitializeDatastore() {
+ false
+ }
+
+ void 'the GORM for MongoDB auto-configuration is registered where Spring Boot reads it'() {
+ expect:
+ MongoDbGormAutoConfiguration.name in ImportCandidates.load(AutoConfiguration, getClass().classLoader).candidates
+ }
+
+ void 'a Spring Boot application gets GORM for MongoDB without importing anything'() {
+ when:
+ ConfigurableApplicationContext context = new SpringApplicationBuilder(DiscoveringApplication)
Review Comment:
Non-blocking. This spec covers the discovery path. The `mongodb/springboot` example test still does not start the application.
`BookControllerSpec` (lines 39-46) builds a standalone MockMvc and takes `BookService` from a `MongoDatastore` that `SpringBootStartMongoExtension` (lines 46-49) constructs by hand. CI packages the example and runs that test, but it still does not start `example.Application` or check that Spring injects `BookService`. No change required for this PR. An optional follow-up is an application-context test for the example.
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#discussion_r4175359265
##########
grails-data-mongodb/boot-plugin/src/test/groovy/org/grails/datastore/gorm/mongodb/boot/autoconfigure/discovered/MongoDbGormAutoConfigurationDiscoverySpec.groovy:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.datastore.gorm.mongodb.boot.autoconfigure.discovered
+
+import grails.gorm.annotation.Entity
+import grails.gorm.transactions.Transactional
+
+import org.springframework.boot.WebApplicationType
+import org.springframework.boot.autoconfigure.AutoConfiguration
+import org.springframework.boot.autoconfigure.SpringBootApplication
+import org.springframework.boot.builder.SpringApplicationBuilder
+import org.springframework.boot.context.annotation.ImportCandidates
+import org.springframework.context.ConfigurableApplicationContext
+import org.springframework.stereotype.Service
+
+import org.apache.grails.testing.mongo.AbstractMongoGrailsExtension
+import org.apache.grails.testing.mongo.AutoStartedMongoSpec
+import org.grails.datastore.gorm.mongodb.boot.autoconfigure.MongoDbGormAutoConfiguration
+import org.grails.datastore.mapping.mongo.MongoDatastore
+
+/**
+ * Spring Boot finds an auto-configuration by reading
+ * {@code META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports}. Nothing here imports
+ * {@link MongoDbGormAutoConfiguration}, so the application gets GORM only if that file names it.
+ */
+class MongoDbGormAutoConfigurationDiscoverySpec extends AutoStartedMongoSpec {
+
+ @Override
+ boolean shouldInitializeDatastore() {
+ false
+ }
+
+ void 'the GORM for MongoDB auto-configuration is registered where Spring Boot reads it'() {
+ expect:
+ MongoDbGormAutoConfiguration.name in ImportCandidates.load(AutoConfiguration, getClass().classLoader).candidates
+ }
+
+ void 'a Spring Boot application gets GORM for MongoDB without importing anything'() {
+ when:
+ ConfigurableApplicationContext context = new SpringApplicationBuilder(DiscoveringApplication)
Review Comment:
Done in edecc4cf47. `ApplicationSpec` starts `example.Application` the way `main` does, against the example's MongoDB container and a database of its own. It checks that Spring injects the `BookService` GORM implements into `BookController`, that the books the application saves on startup are listed over HTTP, and that `/books/It` finds one through the service. With the imports file moved back to `META-INF/services/spring/`, the application fails to start with `No qualifying bean of type 'example.BookService' available`.
Writing it turned up two faults in `SpringBootStartMongoExtension`, fixed in 44eed4de74. Its shared-initializer interceptor never called `proceed()`, so any `@Shared` field a spec initialized itself stayed null. And its `stop()` called `start()` on the container.
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#issuecomment-5973547953
## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/16496?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 59.3700%. Comparing base ([`040cf8a`](https://app.codecov.io/gh/apache/grails-core/commit/040cf8a812a87771c78f87533afc53f53a65461f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`28956fc`](https://app.codecov.io/gh/apache/grails-core/commit/28956fc2674b4aae8e527d1825b0fed82c4dd7a2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 4 commits behind head on 8.0.x.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/grails-core/pull/16496?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## 8.0.x #16496 +/- ##
==================================================
+ Coverage 59.3690% 59.3700% +0.0009%
+ Complexity 24832 24830 -2
==================================================
Files 2171 2171
Lines 108186 108186
Branches 19729 19729
==================================================
+ Hits 64229 64230 +1
+ Misses 35032 35031 -1
Partials 8925 8925
```
[see 2 files with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/16496/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#discussion_r4175565467
##########
grails-test-examples/mongodb/springboot/src/test/groovy/example/SpringBootStartMongoExtension.groovy:
##########
@@ -44,6 +44,8 @@ class SpringBootStartMongoExtension implements IGlobalExtension {
@Override
void visitSpec(SpecInfo spec) {
spec.addSharedInitializerInterceptor { invocation ->
+ // The spec's own shared fields first: this runs in place of their initializers.
+ invocation.proceed()
Review Comment:
Doesn't this mean that setupSpec() will run *before* the value is written to the field below? Shouldn't the invocation occur after write?
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#issuecomment-5976088713
## ✅ All tests passed ✅
🏷️ Commit: a2b567290f17772f58ad390e07fb490be0e4980c
▶️ Tests: 108075 executed
⚪️ Checks: 93/93 completed
---
_Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#discussion_r4175691804
##########
grails-test-examples/mongodb/springboot/src/test/groovy/example/SpringBootStartMongoExtension.groovy:
##########
@@ -44,6 +44,8 @@ class SpringBootStartMongoExtension implements IGlobalExtension {
@Override
void visitSpec(SpecInfo spec) {
spec.addSharedInitializerInterceptor { invocation ->
+ // The spec's own shared fields first: this runs in place of their initializers.
+ invocation.proceed()
Review Comment:
Good catch, fixed in a2b567290f: the datastore is written first, then `proceed()`.
`setupSpec()` itself wasn't affected. `addSharedInitializerInterceptor` wraps only the method that runs the `@Shared` field initializers, and Spock calls `setupSpec()` after that method and the interceptor have finished. What did see null was a `@Shared` initializer that uses the datastore. `SharedDatastoreSpec` now covers both: a `@Shared BookService` initialized from `datastore.getService(BookService)`, and `setupSpec()` doing the same. With the old order the initializer fails with a `NullPointerException`; `setupSpec()` passes either way.
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#issuecomment-5975375524
## ✅ All tests passed ✅
🏷️ Commit: 05b24407b5782df110de1cafd6aae49e97659c5b
▶️ Tests: 107454 executed
⚪️ Checks: 93/93 completed
---
_Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#issuecomment-5975416972
Probably should wait for the tests to finish, but I'm good to merge now.
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#issuecomment-5974018101
## ✅ All tests passed ✅
🏷️ Commit: 28956fc2674b4aae8e527d1825b0fed82c4dd7a2
▶️ Tests: 94007 executed
⚪️ Checks: 85/85 completed
---
_Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #16496:
URL: https://github.com/apache/grails-core/pull/16496#issuecomment-5973814225
<!-- Bito Reply -->
The observation regarding the `BookControllerSpec` is noted. Since this is a non-blocking issue related to the example test suite and does not impact the core discovery path changes in this pull request, no further action is required at this time.
--
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] 8.0 (fix): Register the GORM for MongoDB Spring Boot auto-configuration where Spring Boot reads it [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty merged PR #16496:
URL: https://github.com/apache/grails-core/pull/16496
--
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