Skip to content

Commit 64dada5

Browse files
committed
DATACMNS-306 - RepositoryBeanDefinitionBuilder not correctly sets source.
Previously, the RepositoryBeanDefinitionBuilder did not forward the repository configuration's source instance into the built BeanDefinitions. This is now fixed to enable STS track the origin of the BeanDefinition back to the configuration source (an @Enable-annotation or an XML namespace element).
1 parent e8b2db8 commit 64dada5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/org/springframework/data/repository/config/RepositoryBeanDefinitionBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 the original author or authors.
2+
* Copyright 2012-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -81,6 +81,7 @@ public BeanDefinitionBuilder build(BeanDefinitionRegistry registry, ResourceLoad
8181

8282
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(factoryBeanName);
8383

84+
builder.getRawBeanDefinition().setSource(configuration.getSource());
8485
builder.addPropertyValue("repositoryInterface", configuration.getRepositoryInterface());
8586
builder.addPropertyValue("queryLookupStrategyKey", configuration.getQueryLookupStrategyKey());
8687

src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportIntegrationTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 the original author or authors.
2+
* Copyright 2012-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.*;
2020

2121
import org.junit.Test;
22+
import org.springframework.beans.factory.config.BeanDefinition;
2223
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2324
import org.springframework.context.annotation.Configuration;
2425

@@ -46,4 +47,13 @@ public void testBootstrappingWithInheritedConfigClasses() {
4647
assertThat(context.getBean(MyRepository.class), is(notNullValue()));
4748
assertThat(context.getBean(MyOtherRepository.class), is(notNullValue()));
4849
}
50+
51+
@Test
52+
public void beanDefinitionSourceIsSetForJavaConfigScannedBeans() {
53+
54+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
55+
56+
BeanDefinition definition = context.getBeanDefinition("myRepository");
57+
assertThat(definition.getSource(), is(notNullValue()));
58+
}
4959
}

0 commit comments

Comments
 (0)