EntityScanner is used in several places in our Spring Data integration to provide the Set of entity classes. We should replace this runtime behavior by scanning the target entities at build-time, and write these somewhere so that the runtime can pick it up.

This applies to: Couchbase, Elasticsearch, MongoDB, Neo4j. For some reason, Cassandra isn't using EntityScanner directly (although it looks like it could).

Comment From: snicoll

I've had a first pass to this in https://github.com/snicoll/spring-boot/commit/a1635a0e7a7a8ba76dc6a935858adacc0a8b8fdc. It consists of hiding EntityScanner behind a strategy interface so that we can replace it by something that doesn't do scanning.

There are a few bits missing here:

  • The injection is quite fragile at the moment as we could have multiple EntityProvider beans in the context. It would be better if we could qualify in its type the target data store? I don't see how that's relevant in the actual type though.
  • From an AOT perspective, it would be nice to be able to tell that those beans can be instantiated at build-time. We would be doing this, getting the set and then replacing the bean definition with the hard-coded list.
  • The link between the auto-configuration packages and the scanner are hidden behind BeanFactory. There isn't a dependency that we can use to force the container to resolve the values that we need. As such, we need to be careful when we instantiate that bean at build-time as other beans may not have contributed to the auto-configured packages yet?

Comment From: snicoll

The work in spring-projects/spring-framework#28287 has introduced a PersistenceManagedTypesthat's configured for JPA. For other stores, Spring Data as a ManagedTypes that seems to do what we need.