@EnableReactiveMongoRepositories enables Spring Data's reactive MongoDB repositories. It makes Spring scan for interfaces that extend ReactiveMongoRepository or ReactiveCrudRepository and create non-blocking implementations that return Mono and Flux. In Spring Boot you normally get this behavior from auto-configuration when the reactive MongoDB starter is present, so the annotation is needed mainly for custom package scanning or non-Boot setups.
It belongs to the reactive stack: Spring WebFlux, the MongoDB reactive streams driver and Project Reactor.
Spring Data MongoDB has two repository styles. The blocking style uses @EnableMongoRepositories and MongoRepository. The reactive style uses @EnableReactiveMongoRepositories and returns reactive types, so a request thread is never parked while the database works.
The annotation registers a repository factory bean for each interface found in the scanned packages. Each factory uses a ReactiveMongoTemplate internally to run queries.
Add the reactive starter, not the blocking one.
With these in place, Spring Boot's MongoReactiveRepositoriesAutoConfiguration already scans the package of your main class. Declare the annotation yourself only when you need to change that.
Be aware that declaring it turns off the default auto-configured scan, so every repository package must be listed.
Spring Data derives the query from the method name. The inherited methods such as save, findById and findAll return Mono or Flux.
Nothing runs until something subscribes; WebFlux subscribes to the returned publisher for you. If you call a repository in plain code, you must subscribe or block (for example with StepVerifier in tests), otherwise the query never executes.
basePackages and basePackageClasses choose what to scan.reactiveMongoTemplateRef selects a specific ReactiveMongoTemplate bean when you have several databases.repositoryImplementationPostfix changes the suffix for custom fragments.block() inside a reactive pipeline, because they can stall event loop threads.Usually not. Boot auto-configures reactive MongoDB repositories when the reactive starter is on the classpath.
@EnableMongoRepositories?@EnableMongoRepositories creates blocking repositories, while the reactive annotation creates repositories returning Mono and Flux.
Yes, with separate packages for each style, but a pure reactive stack avoids mixing models.
It works, but you lose most of the benefit because blocking controllers consume the streams. Use it with WebFlux, or on virtual threads with the blocking repositories.
@EnableReactiveMongoRepositories registers non-blocking Spring Data MongoDB repositories that return Mono and Flux. Boot enables it automatically; write it yourself for custom packages or template references, and list every repository package when you do.