Skip to content

Commit 8da9679

Browse files
committed
DATACMNS-1172 - Removed ability to use scanning all packages for repository implementations again.
Kept in a separate commit, so that it's easy to add again by reverting this commit. Removed, as the new behavior is effectively what had been documented as intended behavior all the time. Original pull request: #248.
1 parent da88163 commit 8da9679

8 files changed

+3
-98
lines changed

src/main/java/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSource.java

-15
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
6565
private static final String REPOSITORY_FACTORY_BEAN_CLASS = "repositoryFactoryBeanClass";
6666
private static final String REPOSITORY_BASE_CLASS = "repositoryBaseClass";
6767
private static final String CONSIDER_NESTED_REPOSITORIES = "considerNestedRepositories";
68-
private static final String LIMIT_IMPLEMENTATION_BASE_PACKAGES = "limitImplementationBasePackages";
6968

7069
private final AnnotationMetadata configMetadata;
7170
private final AnnotationMetadata enableAnnotationMetadata;
@@ -322,20 +321,6 @@ public boolean shouldConsiderNestedRepositories() {
322321
return attributes.containsKey(CONSIDER_NESTED_REPOSITORIES) && attributes.getBoolean(CONSIDER_NESTED_REPOSITORIES);
323322
}
324323

325-
/*
326-
* (non-Javadoc)
327-
* @see org.springframework.data.repository.config.RepositoryConfigurationSourceSupport#shouldLimitRepositoryImplementationBasePackages()
328-
*/
329-
@Override
330-
public boolean shouldLimitRepositoryImplementationBasePackages() {
331-
332-
if (!attributes.containsKey(LIMIT_IMPLEMENTATION_BASE_PACKAGES)) {
333-
return true;
334-
}
335-
336-
return attributes.getBoolean(LIMIT_IMPLEMENTATION_BASE_PACKAGES);
337-
}
338-
339324
/*
340325
* (non-Javadoc)
341326
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#getAttribute(java.lang.String)

src/main/java/org/springframework/data/repository/config/DefaultRepositoryConfiguration.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public Streamable<String> getBasePackages() {
7878
*/
7979
@Override
8080
public Streamable<String> getImplementationBasePackages() {
81-
82-
return configurationSource.shouldLimitRepositoryImplementationBasePackages()
83-
? Streamable.of(ClassUtils.getPackageName(getRepositoryInterface()))
84-
: getBasePackages();
81+
return Streamable.of(ClassUtils.getPackageName(getRepositoryInterface()));
8582
}
8683

8784
/*

src/main/java/org/springframework/data/repository/config/RepositoryBeanDefinitionBuilder.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,7 @@ public String getFragmentImplementationClassName() {
311311
* @return
312312
*/
313313
public Iterable<String> getBasePackages() {
314-
315-
return configuration.getConfigurationSource().shouldLimitRepositoryImplementationBasePackages() ? //
316-
Collections.singleton(ClassUtils.getPackageName(fragmentInterfaceName)) : //
317-
configuration.getImplementationBasePackages();
314+
return Collections.singleton(ClassUtils.getPackageName(fragmentInterfaceName));
318315
}
319316

320317
/**

src/main/java/org/springframework/data/repository/config/RepositoryConfigurationSource.java

-11
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@ public interface RepositoryConfigurationSource {
6363
*/
6464
Optional<String> getRepositoryImplementationPostfix();
6565

66-
/**
67-
* Returns whether to limit repository implementation base packages for custom implementation scanning. If
68-
* {@literal true}, then custom implementation scanning considers only the package of the repository/fragment
69-
* interface and its subpackages for a scan. Otherwise, all {@link #getBasePackages()} are scanned for repository
70-
* implementations
71-
*
72-
* @return {@literal true} if base packages are limited to the actual repository package.
73-
* @since 2.0
74-
*/
75-
boolean shouldLimitRepositoryImplementationBasePackages();
76-
7766
/**
7867
* @return
7968
*/

src/main/java/org/springframework/data/repository/config/RepositoryConfigurationSourceSupport.java

-9
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,4 @@ protected Iterable<TypeFilter> getIncludeFilters() {
117117
public boolean shouldConsiderNestedRepositories() {
118118
return false;
119119
}
120-
121-
/*
122-
* (non-Javadoc)
123-
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#isLimitRepositoryImplementationBasePackages()
124-
*/
125-
@Override
126-
public boolean shouldLimitRepositoryImplementationBasePackages() {
127-
return true;
128-
}
129120
}

src/test/java/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSourceUnitTests.java

-11
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ public void returnsConsiderNestedRepositories() {
103103
assertThat(source.shouldConsiderNestedRepositories()).isTrue();
104104
}
105105

106-
@Test // DATACMNS-1172
107-
public void returnsLimitImplementationBasePackages() {
108-
109-
assertThat(getConfigSource(DefaultConfiguration.class).shouldLimitRepositoryImplementationBasePackages()).isTrue();
110-
assertThat(getConfigSource(DefaultConfigurationWithoutBasePackageLimit.class)
111-
.shouldLimitRepositoryImplementationBasePackages()).isFalse();
112-
}
113-
114106
@Test // DATACMNS-456
115107
public void findsStringAttributeByName() {
116108

@@ -164,9 +156,6 @@ static class DefaultConfigurationWithBasePackage {}
164156
@EnableRepositories(considerNestedRepositories = true)
165157
static class DefaultConfigurationWithNestedRepositories {}
166158

167-
@EnableRepositories(limitImplementationBasePackages = false)
168-
static class DefaultConfigurationWithoutBasePackageLimit {}
169-
170159
@EnableRepositories(excludeFilters = { @Filter(Primary.class) })
171160
static class ConfigurationWithExplicitFilter {}
172161

src/test/java/org/springframework/data/repository/config/DefaultRepositoryConfigurationUnitTests.java

-28
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.beans.factory.config.ConstructorArgumentValues;
3535
import org.springframework.beans.factory.support.RootBeanDefinition;
3636
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
37-
import org.springframework.data.util.Streamable;
3837

3938
/**
4039
* Unit tests for {@link DefaultRepositoryConfiguration}.
@@ -84,33 +83,6 @@ public void prefersSourcesRepositoryFactoryBeanClass() {
8483
assertThat(getConfiguration(source).getRepositoryFactoryBeanClassName()).isEqualTo("custom");
8584
}
8685

87-
@Test // DATACMNS-1172
88-
public void limitsImplementationBasePackages() {
89-
90-
when(source.shouldLimitRepositoryImplementationBasePackages()).thenReturn(true);
91-
92-
assertThat(getConfiguration(source, "com.acme.MyRepository").getImplementationBasePackages())
93-
.containsOnly("com.acme");
94-
}
95-
96-
@Test // DATACMNS-1172
97-
public void limitsImplementationBasePackagesOfNestedClass() {
98-
99-
when(source.shouldLimitRepositoryImplementationBasePackages()).thenReturn(true);
100-
101-
assertThat(getConfiguration(source, NestedInterface.class.getName()).getImplementationBasePackages())
102-
.containsOnly("org.springframework.data.repository.config");
103-
}
104-
105-
@Test // DATACMNS-1172
106-
public void shouldNotLimitImplementationBasePackages() {
107-
108-
when(source.getBasePackages()).thenReturn(Streamable.of("com", "org.coyote"));
109-
110-
assertThat(getConfiguration(source, "com.acme.MyRepository").getImplementationBasePackages()).contains("com",
111-
"org.coyote");
112-
}
113-
11486
private DefaultRepositoryConfiguration<RepositoryConfigurationSource> getConfiguration(
11587
RepositoryConfigurationSource source) {
11688
return getConfiguration(source, "com.acme.MyRepository");

src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportUnitTests.java

+1-16
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package org.springframework.data.repository.config;
1717

18-
import static org.mockito.ArgumentMatchers.any;
19-
import static org.mockito.ArgumentMatchers.eq;
18+
import static org.mockito.ArgumentMatchers.*;
2019
import static org.mockito.Mockito.*;
2120

2221
import java.lang.annotation.Annotation;
@@ -96,17 +95,6 @@ public void shouldLimitImplementationBasePackages() {
9695
assertNoBeanDefinitionRegisteredFor("fragmentImpl");
9796
}
9897

99-
@Test // DATACMNS-1172
100-
public void shouldNotLimitImplementationBasePackages() {
101-
102-
AnnotationMetadata metadata = new StandardAnnotationMetadata(UnlimitedImplementationBasePackages.class, true);
103-
104-
registrar.registerBeanDefinitions(metadata, registry);
105-
106-
assertBeanDefinitionRegisteredFor("personRepository");
107-
assertBeanDefinitionRegisteredFor("fragmentImpl");
108-
}
109-
11098
@Test // DATACMNS-360
11199
public void registeredProfileRepositoriesIfProfileActivated() {
112100

@@ -179,7 +167,4 @@ static class FragmentExclusionConfiguration {}
179167

180168
@EnableRepositories(basePackageClasses = FragmentImpl.class)
181169
static class LimitsImplementationBasePackages {}
182-
183-
@EnableRepositories(basePackageClasses = FragmentImpl.class, limitImplementationBasePackages = false)
184-
static class UnlimitedImplementationBasePackages {}
185170
}

0 commit comments

Comments
 (0)