Spring Framework has introduced optimized processing of JPA entities, see https://github.com/spring-projects/spring-framework/issues/28287

To be able to benefit from it, we need to extra the classpath scanning logic so that it can be optimized. It boils down to exposing a PersistenceManagedTypes bean, rather than setting the packages to scan on the EntityManagerBuilder.