Skip to content

Commit aebaa58

Browse files
author
Dave Syer
committed
Add test for user overriding @EnableJpaRepositories
1 parent c8152bf commit aebaa58

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2929
import org.springframework.context.annotation.ComponentScan;
3030
import org.springframework.context.annotation.Configuration;
31+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
3132
import org.springframework.transaction.PlatformTransactionManager;
3233

3334
import static org.junit.Assert.assertNotNull;
@@ -56,10 +57,33 @@ public void testDefaultRepositoryConfiguration() throws Exception {
5657
assertNotNull(this.context.getBean(EntityManagerFactory.class));
5758
}
5859

60+
@Test
61+
public void testOverrideRepositoryConfiguration() throws Exception {
62+
this.context = new AnnotationConfigApplicationContext();
63+
this.context.register(CustomConfiguration.class,
64+
ComponentScanDetectorConfiguration.class,
65+
EmbeddedDataSourceConfiguration.class,
66+
HibernateJpaAutoConfiguration.class,
67+
JpaRepositoriesAutoConfiguration.class,
68+
PropertyPlaceholderAutoConfiguration.class);
69+
this.context.refresh();
70+
assertNotNull(this.context
71+
.getBean(org.springframework.boot.autoconfigure.data.alt.CityRepository.class));
72+
assertNotNull(this.context.getBean(PlatformTransactionManager.class));
73+
assertNotNull(this.context.getBean(EntityManagerFactory.class));
74+
}
75+
5976
@Configuration
6077
@ComponentScan(basePackageClasses = City.class)
6178
protected static class TestConfiguration {
6279

6380
}
6481

82+
@Configuration
83+
@EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityRepository.class)
84+
@ComponentScan(basePackageClasses = City.class)
85+
protected static class CustomConfiguration {
86+
87+
}
88+
6589
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2012-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.data.alt;
18+
19+
import org.springframework.boot.autoconfigure.data.jpa.City;
20+
import org.springframework.data.repository.Repository;
21+
22+
public interface CityRepository extends Repository<City, Long> {
23+
24+
}

0 commit comments

Comments
 (0)