DATAJPA-442 - Enable CDI repositories to be instantiated eagerly.
From the CDI extension we now use the callback newly introduced in Spring Data Commons to enable it to trigger eager initialization. See also: DATACMNS-416.
This commit is contained in:
@@ -33,6 +33,7 @@ import javax.persistence.EntityManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
||||
import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport;
|
||||
|
||||
/**
|
||||
@@ -87,10 +88,13 @@ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
|
||||
Class<?> repositoryType = entry.getKey();
|
||||
Set<Annotation> qualifiers = entry.getValue();
|
||||
|
||||
// Create the bean representing the repository.
|
||||
Bean<?> repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager);
|
||||
CdiRepositoryBean<?> repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager);
|
||||
LOGGER.info("Registering bean for '{}' with qualifiers {}.", repositoryType.getName(), qualifiers);
|
||||
// Register the bean to the container.
|
||||
|
||||
// Register the bean to the extension and the container.
|
||||
registerBean(repositoryBean);
|
||||
afterBeanDiscovery.addBean(repositoryBean);
|
||||
}
|
||||
}
|
||||
@@ -103,7 +107,8 @@ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
* @param beanManager The BeanManager instance.
|
||||
* @return The bean.
|
||||
*/
|
||||
private <T> Bean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) {
|
||||
private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers,
|
||||
BeanManager beanManager) {
|
||||
|
||||
// Determine the entity manager bean which matches the qualifiers of the repository.
|
||||
Bean<EntityManager> entityManagerBean = entityManagers.get(qualifiers);
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.apache.webbeans.cditest.CdiTestContainer;
|
||||
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Integration tests for Spring Data JPA CDI extension.
|
||||
@@ -36,12 +38,17 @@ import org.junit.Test;
|
||||
*/
|
||||
public class CdiExtensionIntegrationTests {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(CdiExtensionIntegrationTests.class);
|
||||
|
||||
static CdiTestContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
|
||||
container = CdiTestContainerLoader.getCdiContainer();
|
||||
container.bootContainer();
|
||||
|
||||
LOGGER.debug("CDI container bootstrapped!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,9 @@ package org.springframework.data.jpa.repository.cdi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.repository.cdi.Eager;
|
||||
|
||||
@Eager
|
||||
public interface PersonRepository {
|
||||
|
||||
List<Person> findAll();
|
||||
|
||||
Reference in New Issue
Block a user