Browse Source

DATACMNS-891 - Repository bean definition registration now exposes repository type in metadata.

We now set an explicit attribute on the BeanDefinition created for every repository factory to allow BeanFactoryPostProcessors to inspect those.
pull/173/head
Oliver Gierke 10 years ago
parent
commit
f75320f33c
  1. 4
      src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java
  2. 67
      src/test/java/org/springframework/data/repository/config/RepositoryConfigurationDelegateUnitTests.java

4
src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java

@ -50,6 +50,8 @@ public class RepositoryConfigurationDelegate { @@ -50,6 +50,8 @@ public class RepositoryConfigurationDelegate {
private static final String MULTIPLE_MODULES = "Multiple Spring Data modules found, entering strict repository configuration mode!";
private static final String MODULE_DETECTION_PACKAGE = "org.springframework.data.**.repository.support";
static final String FACTORY_BEAN_OBJECT_TYPE = "factoryBeanObjectType";
private final RepositoryConfigurationSource configurationSource;
private final ResourceLoader resourceLoader;
private final Environment environment;
@ -140,6 +142,8 @@ public class RepositoryConfigurationDelegate { @@ -140,6 +142,8 @@ public class RepositoryConfigurationDelegate {
configuration.getRepositoryInterface(), extension.getRepositoryFactoryClassName());
}
beanDefinition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, configuration.getRepositoryInterface());
registry.registerBeanDefinition(beanName, beanDefinition);
definitions.add(new BeanComponentDefinition(beanDefinition, beanName));
}

67
src/test/java/org/springframework/data/repository/config/RepositoryConfigurationDelegateUnitTests.java

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
/*
* Copyright 2016 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 static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.data.repository.sample.ProductRepository;
/**
* Unit tests for {@link RepositoryConfigurationDelegate}.
*
* @author Oliver Gierke
* @soundtrack Richard Spaven - Tribute (Whole Other*)
*/
@RunWith(MockitoJUnitRunner.class)
public class RepositoryConfigurationDelegateUnitTests {
@Mock RepositoryConfigurationExtension extension;
/**
* @see DATACMNS-892
*/
@Test
public void registersRepositoryBeanNameAsAttribute() {
StandardEnvironment environment = new StandardEnvironment();
GenericApplicationContext context = new GenericApplicationContext();
RepositoryConfigurationSource configSource = new AnnotationRepositoryConfigurationSource(
new StandardAnnotationMetadata(TestConfig.class, true), EnableRepositories.class, context, environment);
RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(configSource, context, environment);
for (BeanComponentDefinition definition : delegate.registerRepositoriesIn(context, extension)) {
BeanDefinition beanDefinition = definition.getBeanDefinition();
assertThat(beanDefinition.getAttribute(RepositoryConfigurationDelegate.FACTORY_BEAN_OBJECT_TYPE).toString(),
endsWith("Repository"));
}
}
@EnableRepositories(basePackageClasses = ProductRepository.class)
static class TestConfig {}
}
Loading…
Cancel
Save