|
|
|
@ -41,34 +41,38 @@ import org.springframework.data.repository.config.RepositoryConfiguration; |
|
|
|
import org.springframework.data.repository.config.RepositoryConfigurationExtension; |
|
|
|
import org.springframework.data.repository.config.RepositoryConfigurationExtension; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Base {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data |
|
|
|
|
|
|
|
* Repositories. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @author Phillip Webb |
|
|
|
* @author Dave Syer |
|
|
|
* @author Dave Syer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public abstract class AbstractRepositoryConfigurationSourceSupport implements |
|
|
|
public abstract class AbstractRepositoryConfigurationSourceSupport implements |
|
|
|
BeanFactoryAware, ImportBeanDefinitionRegistrar, BeanClassLoaderAware { |
|
|
|
BeanFactoryAware, ImportBeanDefinitionRegistrar, BeanClassLoaderAware { |
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader beanClassLoader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Log logger = LogFactory |
|
|
|
private static Log logger = LogFactory |
|
|
|
.getLog(AbstractRepositoryConfigurationSourceSupport.class); |
|
|
|
.getLog(AbstractRepositoryConfigurationSourceSupport.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader beanClassLoader; |
|
|
|
|
|
|
|
|
|
|
|
private BeanFactory beanFactory; |
|
|
|
private BeanFactory beanFactory; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, |
|
|
|
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, |
|
|
|
final BeanDefinitionRegistry registry) { |
|
|
|
final BeanDefinitionRegistry registry) { |
|
|
|
|
|
|
|
|
|
|
|
final ResourceLoader resourceLoader = new DefaultResourceLoader(); |
|
|
|
ResourceLoader resourceLoader = new DefaultResourceLoader(); |
|
|
|
final AnnotationRepositoryConfigurationSource configurationSource = getConfigurationSource(); |
|
|
|
AnnotationRepositoryConfigurationSource configurationSource = getConfigurationSource(); |
|
|
|
final RepositoryConfigurationExtension extension = getRepositoryConfigurationExtension(); |
|
|
|
RepositoryConfigurationExtension extension = getRepositoryConfigurationExtension(); |
|
|
|
extension.registerBeansForRoot(registry, configurationSource); |
|
|
|
extension.registerBeansForRoot(registry, configurationSource); |
|
|
|
|
|
|
|
|
|
|
|
final RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator(); |
|
|
|
RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator(); |
|
|
|
generator.setBeanClassLoader(this.beanClassLoader); |
|
|
|
generator.setBeanClassLoader(this.beanClassLoader); |
|
|
|
|
|
|
|
|
|
|
|
Collection<RepositoryConfiguration<AnnotationRepositoryConfigurationSource>> repositoryConfigurations = extension |
|
|
|
Collection<RepositoryConfiguration<AnnotationRepositoryConfigurationSource>> repositoryConfigurations = extension |
|
|
|
.getRepositoryConfigurations(configurationSource, resourceLoader); |
|
|
|
.getRepositoryConfigurations(configurationSource, resourceLoader); |
|
|
|
|
|
|
|
|
|
|
|
for (final RepositoryConfiguration<AnnotationRepositoryConfigurationSource> repositoryConfiguration : repositoryConfigurations) { |
|
|
|
for (RepositoryConfiguration<AnnotationRepositoryConfigurationSource> repositoryConfiguration : repositoryConfigurations) { |
|
|
|
RepositoryBeanDefinitionBuilder builder = new RepositoryBeanDefinitionBuilder( |
|
|
|
RepositoryBeanDefinitionBuilder builder = new RepositoryBeanDefinitionBuilder( |
|
|
|
repositoryConfiguration, extension); |
|
|
|
repositoryConfiguration, extension); |
|
|
|
BeanDefinitionBuilder definitionBuilder = builder.build(registry, |
|
|
|
BeanDefinitionBuilder definitionBuilder = builder.build(registry, |
|
|
|
@ -82,21 +86,11 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private AnnotationRepositoryConfigurationSource getConfigurationSource() { |
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata( |
|
|
|
this.beanClassLoader = classLoader; |
|
|
|
getConfiguration(), true); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract RepositoryConfigurationExtension getRepositoryConfigurationExtension(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract AnnotationRepositoryConfigurationSource getConfigurationSource(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected AnnotationRepositoryConfigurationSource getConfigurationSource( |
|
|
|
|
|
|
|
Class<?> annotated, Class<? extends Annotation> annotation) { |
|
|
|
|
|
|
|
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(annotated, |
|
|
|
|
|
|
|
true); |
|
|
|
|
|
|
|
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource( |
|
|
|
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource( |
|
|
|
metadata, annotation) { |
|
|
|
metadata, getAnnotation()) { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public java.lang.Iterable<String> getBasePackages() { |
|
|
|
public java.lang.Iterable<String> getBasePackages() { |
|
|
|
@ -117,6 +111,26 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements |
|
|
|
return basePackages; |
|
|
|
return basePackages; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The Spring Data annotation used to enable the particular repository support. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected abstract Class<? extends Annotation> getAnnotation(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The configuration class that will be used by Spring Boot as a template. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected abstract Class<?> getConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The {@link RepositoryConfigurationExtension} for the particular repository support. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected abstract RepositoryConfigurationExtension getRepositoryConfigurationExtension(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
|
|
|
|
this.beanClassLoader = classLoader; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
|
|
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
|