From 64dada589644e64444d93c0ec3162af20fc91fb5 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 28 Mar 2013 18:53:17 +0100 Subject: [PATCH] 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). --- .../config/RepositoryBeanDefinitionBuilder.java | 3 ++- ...anDefinitionRegistrarSupportIntegrationTests.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryBeanDefinitionBuilder.java b/src/main/java/org/springframework/data/repository/config/RepositoryBeanDefinitionBuilder.java index fd8c74638..2de672515 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryBeanDefinitionBuilder.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryBeanDefinitionBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2013 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. @@ -81,6 +81,7 @@ public class RepositoryBeanDefinitionBuilder { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(factoryBeanName); + builder.getRawBeanDefinition().setSource(configuration.getSource()); builder.addPropertyValue("repositoryInterface", configuration.getRepositoryInterface()); builder.addPropertyValue("queryLookupStrategyKey", configuration.getQueryLookupStrategyKey()); diff --git a/src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportIntegrationTests.java b/src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportIntegrationTests.java index 8cf158d08..342c7a0b3 100644 --- a/src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportIntegrationTests.java +++ b/src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2013 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. @@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import org.junit.Test; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; @@ -46,4 +47,13 @@ public class RepositoryBeanDefinitionRegistrarSupportIntegrationTests { assertThat(context.getBean(MyRepository.class), is(notNullValue())); assertThat(context.getBean(MyOtherRepository.class), is(notNullValue())); } + + @Test + public void beanDefinitionSourceIsSetForJavaConfigScannedBeans() { + + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class); + + BeanDefinition definition = context.getBeanDefinition("myRepository"); + assertThat(definition.getSource(), is(notNullValue())); + } }