|
18 | 18 | import static org.springframework.data.jpa.repository.config.BeanDefinitionNames.*;
|
19 | 19 |
|
20 | 20 | import jakarta.persistence.Entity;
|
| 21 | +import jakarta.persistence.EntityManagerFactory; |
21 | 22 | import jakarta.persistence.MappedSuperclass;
|
22 | 23 | import jakarta.persistence.PersistenceContext;
|
23 | 24 | import jakarta.persistence.PersistenceUnit;
|
|
38 | 39 | import org.springframework.aot.generate.GenerationContext;
|
39 | 40 | import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
|
40 | 41 | import org.springframework.beans.factory.config.BeanDefinition;
|
| 42 | +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
41 | 43 | import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
42 | 44 | import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
43 | 45 | import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
@@ -325,15 +327,20 @@ static boolean isActive(@Nullable ClassLoader classLoader) {
|
325 | 327 | */
|
326 | 328 | public static class JpaRepositoryRegistrationAotProcessor extends RepositoryRegistrationAotProcessor {
|
327 | 329 |
|
328 |
| - protected RepositoryContributor contribute(AotRepositoryContext repositoryContext, GenerationContext generationContext) { |
| 330 | + protected @Nullable RepositoryContributor contribute(AotRepositoryContext repositoryContext, |
| 331 | + GenerationContext generationContext) { |
329 | 332 |
|
330 |
| - // don't register domain types nor annotations. |
331 |
| - |
332 |
| - if (!AotContext.aotGeneratedRepositoriesEnabled()) { |
| 333 | + boolean enabled = Boolean.parseBoolean( |
| 334 | + repositoryContext.getEnvironment().getProperty(AotContext.GENERATED_REPOSITORIES_ENABLED, "false")); |
| 335 | + if (!enabled) { |
333 | 336 | return null;
|
334 | 337 | }
|
335 | 338 |
|
336 |
| - return new JpaRepositoryContributor(repositoryContext); |
| 339 | + ConfigurableListableBeanFactory beanFactory = repositoryContext.getBeanFactory(); |
| 340 | + EntityManagerFactory emf = beanFactory.getBeanProvider(EntityManagerFactory.class).getIfAvailable(); |
| 341 | + |
| 342 | + return emf != null ? new JpaRepositoryContributor(repositoryContext, emf) |
| 343 | + : new JpaRepositoryContributor(repositoryContext); |
337 | 344 | }
|
338 | 345 |
|
339 | 346 | @Nullable
|
|
0 commit comments