diff --git a/src/test/java/org/springframework/data/jpa/domain/sample/Role.java b/src/test/java/org/springframework/data/jpa/domain/sample/Role.java index 19b77d318..e22d36a05 100644 --- a/src/test/java/org/springframework/data/jpa/domain/sample/Role.java +++ b/src/test/java/org/springframework/data/jpa/domain/sample/Role.java @@ -22,7 +22,6 @@ package org.springframework.data.jpa.domain.sample; */ public class Role { - private static final long serialVersionUID = -8832631113344035104L; private static final String PREFIX = "ROLE_"; private Integer id; diff --git a/src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java b/src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java index f15dbe217..abea7664d 100644 --- a/src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java @@ -21,17 +21,15 @@ import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleDepartment; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployee; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployeePK; import org.springframework.data.jpa.domain.sample.IdClassExampleDepartment; import org.springframework.data.jpa.domain.sample.IdClassExampleEmployee; import org.springframework.data.jpa.domain.sample.IdClassExampleEmployeePK; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.sample.EmployeeRepositoryWithEmbeddedId; import org.springframework.data.jpa.repository.sample.EmployeeRepositoryWithIdClass; +import org.springframework.data.jpa.repository.sample.SampleConfig; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -43,15 +41,10 @@ import org.springframework.transaction.annotation.Transactional; * @author Thomas Darimont */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@ContextConfiguration(classes = SampleConfig.class) @Transactional public class DataJpa269RepositoryWithCompositeKeyTests { - @Configuration - @ImportResource("classpath:infrastructure.xml") - @EnableJpaRepositories - static interface Config {} - @Autowired EmployeeRepositoryWithIdClass employeeRepositoryWithIdClass; @Autowired EmployeeRepositoryWithEmbeddedId employeeRepositoryWithEmbeddedId; diff --git a/src/test/java/org/springframework/data/jpa/repository/JavaConfigUserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/JavaConfigUserRepositoryTests.java index d41a369a5..28c712e95 100644 --- a/src/test/java/org/springframework/data/jpa/repository/JavaConfigUserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/JavaConfigUserRepositoryTests.java @@ -25,7 +25,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.PropertiesFactoryBean; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -53,10 +53,8 @@ public class JavaConfigUserRepositoryTests extends UserRepositoryTests { @ImportResource("classpath:infrastructure.xml") static class Config { - @PersistenceContext - EntityManager entityManager; - @Autowired - BeanFactory beanFactory; + @PersistenceContext EntityManager entityManager; + @Autowired BeanFactory beanFactory; @Bean public UserRepository userRepository() throws IOException { @@ -88,12 +86,13 @@ public class JavaConfigUserRepositoryTests extends UserRepositoryTests { @Test(expected = NoSuchBeanDefinitionException.class) public void doesNotPickUpJpaRepository() { - ApplicationContext context = new AnnotationConfigApplicationContext(JpaRepositoryConfig.class); + ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(JpaRepositoryConfig.class); context.getBean("jpaRepository"); + context.close(); } @Configuration - @EnableJpaRepositories + @EnableJpaRepositories(basePackageClasses = UserRepository.class) @ImportResource("classpath:infrastructure.xml") static class JpaRepositoryConfig { diff --git a/src/test/java/org/springframework/data/jpa/repository/MappedTypeRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/MappedTypeRepositoryIntegrationTests.java index 463bac057..7b0f2f0ae 100644 --- a/src/test/java/org/springframework/data/jpa/repository/MappedTypeRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/MappedTypeRepositoryIntegrationTests.java @@ -23,14 +23,12 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; import org.springframework.data.jpa.domain.sample.ConcreteType1; import org.springframework.data.jpa.domain.sample.ConcreteType2; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.sample.ConcreteRepository1; import org.springframework.data.jpa.repository.sample.ConcreteRepository2; import org.springframework.data.jpa.repository.sample.MappedTypeRepository; +import org.springframework.data.jpa.repository.sample.SampleConfig; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -42,14 +40,9 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@ContextConfiguration(classes = SampleConfig.class) public class MappedTypeRepositoryIntegrationTests { - @Configuration - @ImportResource("classpath:infrastructure.xml") - @EnableJpaRepositories - static class Config {} - @Autowired ConcreteRepository1 concreteRepository1; @Autowired ConcreteRepository2 concreteRepository2; diff --git a/src/test/java/org/springframework/data/jpa/repository/RedeclaringRepositoryMethodsTests.java b/src/test/java/org/springframework/data/jpa/repository/RedeclaringRepositoryMethodsTests.java index 5ea7f7bc9..844ce929c 100644 --- a/src/test/java/org/springframework/data/jpa/repository/RedeclaringRepositoryMethodsTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/RedeclaringRepositoryMethodsTests.java @@ -24,13 +24,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.sample.User; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.sample.RedeclaringRepositoryMethodsRepository; +import org.springframework.data.jpa.repository.sample.SampleConfig; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -39,15 +37,10 @@ import org.springframework.transaction.annotation.Transactional; * @author Thomas Darimont */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@ContextConfiguration(classes = SampleConfig.class) @Transactional public class RedeclaringRepositoryMethodsTests { - @Configuration - @ImportResource("classpath:infrastructure.xml") - @EnableJpaRepositories - static class Config {} - @Autowired RedeclaringRepositoryMethodsRepository repository; User ollie, tom; diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository1.java b/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository1.java index fd27000bc..280a506a4 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository1.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository1.java @@ -15,11 +15,13 @@ */ package org.springframework.data.jpa.repository.sample; +import org.springframework.context.annotation.Lazy; import org.springframework.data.jpa.domain.sample.ConcreteType1; /** * @author Thomas Darimont */ +@Lazy public interface ConcreteRepository1 extends MappedTypeRepository { } diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository2.java b/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository2.java index 41524d83b..4452ece94 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository2.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/ConcreteRepository2.java @@ -15,11 +15,13 @@ */ package org.springframework.data.jpa.repository.sample; +import org.springframework.context.annotation.Lazy; import org.springframework.data.jpa.domain.sample.ConcreteType2; /** * @author Thomas Darimont */ +@Lazy public interface ConcreteRepository2 extends MappedTypeRepository { } diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithEmbeddedId.java b/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithEmbeddedId.java index 7722c4861..912a9f2c5 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithEmbeddedId.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithEmbeddedId.java @@ -15,6 +15,7 @@ */ package org.springframework.data.jpa.repository.sample; +import org.springframework.context.annotation.Lazy; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployee; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployeePK; import org.springframework.data.jpa.repository.JpaRepository; @@ -24,5 +25,6 @@ import org.springframework.data.jpa.repository.JpaRepository; * * @author Thomas Darimont */ +@Lazy public interface EmployeeRepositoryWithEmbeddedId extends JpaRepository {} diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithIdClass.java b/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithIdClass.java index 1656fde15..7f67eedee 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithIdClass.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/EmployeeRepositoryWithIdClass.java @@ -15,6 +15,7 @@ */ package org.springframework.data.jpa.repository.sample; +import org.springframework.context.annotation.Lazy; import org.springframework.data.jpa.domain.sample.IdClassExampleEmployee; import org.springframework.data.jpa.domain.sample.IdClassExampleEmployeePK; import org.springframework.data.jpa.repository.JpaRepository; @@ -24,4 +25,5 @@ import org.springframework.data.jpa.repository.JpaRepository; * * @author Thomas Darimont */ +@Lazy public interface EmployeeRepositoryWithIdClass extends JpaRepository {} diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/MappedTypeRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/MappedTypeRepository.java index 5a9ce4a0b..e387a653d 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/MappedTypeRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/MappedTypeRepository.java @@ -17,6 +17,7 @@ package org.springframework.data.jpa.repository.sample; import java.util.List; +import org.springframework.context.annotation.Lazy; import org.springframework.data.jpa.domain.sample.AbstractMappedType; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -24,6 +25,7 @@ import org.springframework.data.jpa.repository.Query; /** * @author Thomas Darimont */ +@Lazy public interface MappedTypeRepository extends JpaRepository { @Query("from #{#entityName} t where t.attribute1=?1") diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/ParentRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/ParentRepository.java index 33bf6def7..82d3a83a7 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/ParentRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/ParentRepository.java @@ -15,9 +15,10 @@ */ package org.springframework.data.jpa.repository.sample; +import org.springframework.context.annotation.Lazy; import org.springframework.data.jpa.domain.sample.Parent; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -public interface ParentRepository extends JpaRepository, JpaSpecificationExecutor { -} +@Lazy +public interface ParentRepository extends JpaRepository, JpaSpecificationExecutor {} diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/SampleConfig.java b/src/test/java/org/springframework/data/jpa/repository/sample/SampleConfig.java new file mode 100644 index 000000000..b84035952 --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/repository/sample/SampleConfig.java @@ -0,0 +1,30 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.repository.sample; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +/** + * @author Oliver Gierke + */ +@Configuration +@ImportResource("classpath:infrastructure.xml") +@EnableJpaRepositories +public class SampleConfig { + +} diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 2c107f047..6730ec0c1 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -1,6 +1,7 @@ + org.springframework.data.jpa.domain.sample.AbstractMappedType org.springframework.data.jpa.domain.AbstractPersistable org.springframework.data.jpa.domain.AbstractAuditable org.springframework.data.jpa.domain.sample.Account diff --git a/src/test/resources/config/lookup-strategies-context.xml b/src/test/resources/config/lookup-strategies-context.xml index dbfa58d41..541a85a80 100644 --- a/src/test/resources/config/lookup-strategies-context.xml +++ b/src/test/resources/config/lookup-strategies-context.xml @@ -2,11 +2,15 @@ + xmlns:repository="http://www.springframework.org/schema/data/repository" + xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> - + + +