diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector.java index b321dd11f8..4ad872279f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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. @@ -27,6 +27,7 @@ import org.springframework.context.annotation.ImportSelector; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.type.AnnotationMetadata; import org.springframework.util.MultiValueMap; +import org.springframework.util.StringUtils; /** * Import selector that sets up binding of external properties to configuration classes @@ -39,6 +40,7 @@ import org.springframework.util.MultiValueMap; * {@link ConfigurationProperties} bean of each unique type). * * @author Dave Syer + * @author Christian Dupuis */ class EnableConfigurationPropertiesImportSelector implements ImportSelector { @@ -67,13 +69,25 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector { EnableConfigurationProperties.class.getName(), false); List> types = collectClasses(attributes.get("value")); for (Class type : types) { - String name = type.getName(); + String prefix = extractPrefix(type); + String name = (StringUtils.hasText(prefix) ? prefix + + ".CONFIGURATION_PROPERTIES" : type.getName()); if (!registry.containsBeanDefinition(name)) { registerBeanDefinition(registry, type, name); } } } + private String extractPrefix(Class type) { + ConfigurationProperties annotation = AnnotationUtils.findAnnotation(type, + ConfigurationProperties.class); + if (annotation != null) { + return (StringUtils.hasLength(annotation.value()) ? annotation.value() + : annotation.name()); + } + return ""; + } + private List> collectClasses(List list) { ArrayList> result = new ArrayList>(); for (Object object : list) {