Skip to content

Introduce PropertiesBasedNamedQueriesFactoryBean to reduce bean indirections #2596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
package org.springframework.data.repository.config;

import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
Expand Down Expand Up @@ -128,8 +131,9 @@ public BeanDefinitionBuilder build(RepositoryConfiguration<?> configuration) {

fragmentsBuilder.addConstructorArgValue(fragmentBeanNames);

builder.addPropertyValue("repositoryFragments",
ParsingUtils.getSourceBeanDefinition(fragmentsBuilder, configuration.getSource()));
String fragmentsBeanName = BeanDefinitionReaderUtils.uniqueBeanName(extension.getModuleName().toLowerCase(Locale.ROOT) + ".repo-fragments", registry);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to include the repository name for easier correlation as the fragments are correlated to an individual repository.

registry.registerBeanDefinition(fragmentsBeanName, fragmentsBuilder.getBeanDefinition());
builder.addPropertyValue("repositoryFragments", new RuntimeBeanReference(fragmentsBeanName));

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ void registersBeanDefinitionForFoundBean() {
assertNoBeanDefinitionRegisteredFor("profileRepository");
}


@Test // GH-2584
void shouldExposeFragmentsAsBean() {

AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);

registrar.registerBeanDefinitions(metadata, registry);
verify(registry, atLeast(1)).registerBeanDefinition(eq("commons.repo-fragments#0"), any(BeanDefinition.class));
}

@Test // DATACMNS-1754
void registersBeanDefinitionForNestedRepositories() {

Expand Down