DATAJPA-319 - Use default CDI repository scope (application).

Don't inherit the scope of the repository from the EntityManager but let it be the default (application scope singleton).
This commit is contained in:
Oliver Gierke
2013-03-20 17:03:48 +01:00
parent 40caa97808
commit d364b441b4
5 changed files with 28 additions and 18 deletions

View File

@@ -32,7 +32,6 @@ import org.springframework.util.Assert;
*
* @author Dirk Mahler
* @author Oliver Gierke
*
* @param <T> The type of the repository.
*/
class JpaRepositoryBean<T> extends CdiRepositoryBean<T> {
@@ -69,14 +68,4 @@ class JpaRepositoryBean<T> extends CdiRepositoryBean<T> {
JpaRepositoryFactory factory = new JpaRepositoryFactory(entityManager);
return factory.getRepository(repositoryType);
}
/*
* (non-Javadoc)
* @see javax.enterprise.inject.spi.Bean#getScope()
*/
public Class<? extends Annotation> getScope() {
// The repository uses the same scope as the associated EntityManager.
return entityManagerBean.getScope();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,14 @@
*/
package org.springframework.data.jpa.repository.cdi;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.spi.Bean;
import org.apache.webbeans.cditest.CdiTestContainer;
import org.apache.webbeans.cditest.CdiTestContainerLoader;
import org.junit.BeforeClass;
@@ -36,6 +44,19 @@ public class CdiExtensionintegrationTests {
container.bootContainer();
}
/**
* @see DATAJPA-319
*/
@Test
@SuppressWarnings("rawtypes")
public void foo() {
Set<Bean<?>> beans = container.getBeanManager().getBeans(PersonRepository.class);
assertThat(beans, hasSize(1));
assertThat(beans.iterator().next().getScope(), is(equalTo((Class) ApplicationScoped.class)));
}
@Test
public void saveAndFindAll() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@ package org.springframework.data.jpa.repository.cdi;
import java.util.List;
interface PersonRepository {
public interface PersonRepository {
List<Person> findAll();

View File

@@ -18,6 +18,6 @@ package org.springframework.data.jpa.repository.cdi;
import org.springframework.data.repository.Repository;
@PersonDB
interface QualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
public interface QualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,6 @@ package org.springframework.data.jpa.repository.cdi;
import org.springframework.data.repository.Repository;
interface UnqualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
public interface UnqualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
}