mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Upgraded to Spring Data Codd
Update AbstractRepositoryConfigurationSourceSupport to use the newly introduced RepositoryConfigurationDelegate instead of effectively reimplementing Spring Data Commons functionality which was prone to changes in the API (code that wasn't considered to be API in the first place). Switch from implementing BeanClassLoaderAware to ResourceLoaderAware to avoid having to set up a DefaultResourceLoader which should also improve IDE integration. Fixes gh-236
This commit is contained in:
parent
be73535611
commit
929bd902be
@ -17,26 +17,21 @@
|
||||
package org.springframework.boot.autoconfigure.data;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
|
||||
import org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder;
|
||||
import org.springframework.data.repository.config.RepositoryBeanNameGenerator;
|
||||
import org.springframework.data.repository.config.RepositoryConfiguration;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationDelegate;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
|
||||
/**
|
||||
@ -48,10 +43,10 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class AbstractRepositoryConfigurationSourceSupport implements
|
||||
BeanFactoryAware, ImportBeanDefinitionRegistrar, BeanClassLoaderAware,
|
||||
BeanFactoryAware, ImportBeanDefinitionRegistrar, ResourceLoaderAware,
|
||||
EnvironmentAware {
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@ -60,45 +55,21 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
|
||||
final BeanDefinitionRegistry registry) {
|
||||
|
||||
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
AnnotationRepositoryConfigurationSource configurationSource = getConfigurationSource();
|
||||
RepositoryConfigurationExtension extension = getRepositoryConfigurationExtension();
|
||||
extension.registerBeansForRoot(registry, configurationSource);
|
||||
|
||||
RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator();
|
||||
generator.setBeanClassLoader(this.beanClassLoader);
|
||||
|
||||
Collection<RepositoryConfiguration<AnnotationRepositoryConfigurationSource>> repositoryConfigurations = extension
|
||||
.getRepositoryConfigurations(configurationSource, resourceLoader);
|
||||
|
||||
for (RepositoryConfiguration<AnnotationRepositoryConfigurationSource> repositoryConfiguration : repositoryConfigurations) {
|
||||
RepositoryBeanDefinitionBuilder builder = new RepositoryBeanDefinitionBuilder(
|
||||
repositoryConfiguration, extension);
|
||||
BeanDefinitionBuilder definitionBuilder = builder.build(registry,
|
||||
resourceLoader);
|
||||
extension.postProcess(definitionBuilder, configurationSource);
|
||||
|
||||
String beanName = generator.generateBeanName(
|
||||
definitionBuilder.getBeanDefinition(), registry);
|
||||
registry.registerBeanDefinition(beanName,
|
||||
definitionBuilder.getBeanDefinition());
|
||||
}
|
||||
new RepositoryConfigurationDelegate(getConfigurationSource(), this.resourceLoader)
|
||||
.registerRepositoriesIn(registry, getRepositoryConfigurationExtension());
|
||||
}
|
||||
|
||||
private AnnotationRepositoryConfigurationSource getConfigurationSource() {
|
||||
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(
|
||||
getConfiguration(), true);
|
||||
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(
|
||||
metadata, getAnnotation(), this.environment) {
|
||||
|
||||
return new AnnotationRepositoryConfigurationSource(metadata, getAnnotation(),
|
||||
this.environment) {
|
||||
@Override
|
||||
public java.lang.Iterable<String> getBasePackages() {
|
||||
return AbstractRepositoryConfigurationSourceSupport.this
|
||||
.getBasePackages();
|
||||
};
|
||||
};
|
||||
return configurationSource;
|
||||
}
|
||||
|
||||
protected Iterable<String> getBasePackages() {
|
||||
@ -121,8 +92,8 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
|
||||
protected abstract RepositoryConfigurationExtension getRepositoryConfigurationExtension();
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
public void setResourceLoader(ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -134,4 +105,5 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,12 +21,15 @@ import javax.persistence.EntityManagerFactory;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
import org.springframework.boot.autoconfigure.data.alt.CityMongoDbRepository;
|
||||
import org.springframework.boot.autoconfigure.data.jpa.City;
|
||||
import org.springframework.boot.autoconfigure.data.jpa.CityRepository;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@ -78,7 +81,7 @@ public class JpaRepositoriesAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityJpaRepository.class)
|
||||
@EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityJpaRepository.class, excludeFilters = { @Filter(type = FilterType.ASSIGNABLE_TYPE, value = CityMongoDbRepository.class) })
|
||||
@TestAutoConfigurationPackage(City.class)
|
||||
protected static class CustomConfiguration {
|
||||
|
||||
|
@ -45,8 +45,8 @@
|
||||
<spring.version>4.0.1.RELEASE</spring.version>
|
||||
<spring-integration.version>3.0.0.RELEASE</spring-integration.version>
|
||||
<spring-batch.version>2.2.4.RELEASE</spring-batch.version>
|
||||
<spring-data-jpa.version>1.4.3.RELEASE</spring-data-jpa.version>
|
||||
<spring-data-mongodb.version>1.3.3.RELEASE</spring-data-mongodb.version>
|
||||
<spring-data-jpa.version>1.5.0.RC1</spring-data-jpa.version>
|
||||
<spring-data-mongodb.version>1.4.0.RC1</spring-data-mongodb.version>
|
||||
<spring-data-redis.version>1.1.1.RELEASE</spring-data-redis.version>
|
||||
<spring-rabbit.version>1.2.1.RELEASE</spring-rabbit.version>
|
||||
<spring-mobile.version>1.1.0.RELEASE</spring-mobile.version>
|
||||
|
Loading…
Reference in New Issue
Block a user