DATACMNS-1147 - Do not consider @NoRepositoryBean interfaces as fragment interfaces.
We filter interfaces annotated with @NoRepositoryBean from fragment interface candidates and not longer scan for implementations of these. Extending a base repository usually requires an interface which is used as base interface instead of Repository/CrudRepository in user repositories. If the naming scheme of the extended interface and the implementation fits to fragment interfaces, then we previously registered the class additionally as fragment implementation. The bean registration caused container startup failures because of unsatisfied dependencies or would shadow the base repository implementation. Original pull request #239.
This commit is contained in:
committed by
Oliver Gierke
parent
22b6971318
commit
d657b17e74
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2017 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.repository.config;
|
||||
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
/**
|
||||
* Interface specifying customizations for a base repository implementation.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface ExcludedRepository<T, ID> extends Repository<T, ID> {
|
||||
String getImplementationId();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2017 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.repository.config;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ExcludedRepositoryImpl<T, ID> implements ExcludedRepository<T, ID> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.ExcludedRepository#getImplementationId()
|
||||
*/
|
||||
@Override
|
||||
public String getImplementationId() {
|
||||
return getClass().getName();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
@@ -71,6 +73,17 @@ public class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
assertNoBeanDefinitionRegisteredFor("profileRepository");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1147
|
||||
public void registersBeanDefinitionWithoutFragmentImplementations() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(FragmentExclusionConfiguration.class, true);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
|
||||
assertBeanDefinitionRegisteredFor("repositoryWithFragmentExclusion");
|
||||
assertNoBeanDefinitionRegisteredFor("excludedRepositoryImpl");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-360
|
||||
public void registeredProfileRepositoriesIfProfileActivated() {
|
||||
|
||||
@@ -135,4 +148,11 @@ public class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
return "commons";
|
||||
}
|
||||
}
|
||||
|
||||
@EnableRepositories(
|
||||
includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = RepositoryWithFragmentExclusion.class),
|
||||
basePackageClasses = RepositoryWithFragmentExclusion.class)
|
||||
static class FragmentExclusionConfiguration {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2017 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.repository.config;
|
||||
|
||||
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSourceUnitTests.Person;
|
||||
|
||||
/**
|
||||
* Repository with customized base base interface.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface RepositoryWithFragmentExclusion extends ExcludedRepository<Person, Long> {}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -18,7 +18,10 @@ package org.springframework.data.repository.config;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
|
||||
@EnableRepositories(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = MyOtherRepository.class), basePackageClasses = AnnotationRepositoryConfigurationSourceUnitTests.class)
|
||||
@EnableRepositories(
|
||||
excludeFilters = { @Filter(type = FilterType.ASSIGNABLE_TYPE, value = MyOtherRepository.class),
|
||||
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = ExcludedRepository.class) },
|
||||
basePackageClasses = AnnotationRepositoryConfigurationSourceUnitTests.class)
|
||||
class SampleConfiguration {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user