Spring-boot: Reactive MongoDB repository initialized twice

Created on 27 Nov 2019  路  5Comments  路  Source: spring-projects/spring-boot

I just generated a new project via Spring Initializr that has the reactive Spring Data MongoDB added.

It's available here as a very simple example:
https://github.com/laxika/spring-data-init-twice-error

The result is:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.1.RELEASE)

2019-11-27 15:16:52.925  INFO 8984 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication on DESKTOP-B60RE8G with PID 8984 (started by Gyula Lakatos in C:\Users\Gyula Lakatos\Development\demo)
2019-11-27 15:16:52.927  INFO 8984 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2019-11-27 15:16:53.162  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-11-27 15:16:53.172  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7ms. Found 0 repository interfaces.
2019-11-27 15:16:53.175  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-11-27 15:16:53.176  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 0ms. Found 0 repository interfaces.
2019-11-27 15:16:53.383  INFO 8984 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-11-27 15:16:53.410  INFO 8984 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:3609}] to localhost:27017
2019-11-27 15:16:53.413  INFO 8984 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 1]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1873500}
2019-11-27 15:16:53.449  WARN 8984 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-11-27 15:16:53.449  WARN 8984 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-11-27 15:16:53.465  WARN 8984 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-11-27 15:16:53.465  WARN 8984 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2019-11-27 15:16:53.505  INFO 8984 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-11-27 15:16:53.518  INFO 8984 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:2, serverValue:3610}] to localhost:27017
2019-11-27 15:16:53.520  INFO 8984 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 1]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1197800}
2019-11-27 15:16:53.544  INFO 8984 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 0.816 seconds (JVM running for 1.503)

Process finished with exit code 0

For some reason, the repository scanning happens twice.

2019-11-27 15:16:53.162  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-11-27 15:16:53.172  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7ms. Found 0 repository interfaces.
2019-11-27 15:16:53.175  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-11-27 15:16:53.176  INFO 8984 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 0ms. Found 0 repository interfaces.

I guess this is not expected right?

invalid

Most helpful comment

We would end up with messages like:

2019-11-29 10:39:34.255  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
2019-11-29 10:39:34.265  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data Reactive MongoDB repository scanning in 7ms. Found 0 repository interfaces.
2019-11-29 10:39:34.269  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2019-11-29 10:39:34.269  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data MongoDB repository scanning in 0ms. Found 0 repository interfaces.

All 5 comments

Thanks for the sample. This is working as designed as both reactive and imperative Mongo repositories are being bootstrapped. If you want only one type to be used, you can set spring.data.mongo.repositories.type to either imperative or reactive.

@wilkinsona Thanks for the quick reply. It would simplify things a bit if Spring could print the repository type that is being initialized.

That's a good idea. I agree that it would simplify things. I think it might be possible with some information that the configuration source could provide. It's a change that would have to be made in Spring Data so let's see what @mp911de thinks.

It makes sense to add the module name. The code path has also access to the proper name (MongoDB and Reactive MongoDB; Other modules can also provide proper names) to disambiguate what's going on. I filed DATACMNS-1629 to improve our logging messages.

We would end up with messages like:

2019-11-29 10:39:34.255  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
2019-11-29 10:39:34.265  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data Reactive MongoDB repository scanning in 7ms. Found 0 repository interfaces.
2019-11-29 10:39:34.269  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2019-11-29 10:39:34.269  INFO 28409 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data MongoDB repository scanning in 0ms. Found 0 repository interfaces.
Was this page helpful?
0 / 5 - 0 ratings