@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2012 - 201 6 the original author or authors .
* Copyright 2012 - 201 7 the original author or authors .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -19,6 +19,7 @@ package org.springframework.boot.context.properties;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.List ;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory ;
import org.springframework.beans.factory.support.AbstractBeanDefinition ;
import org.springframework.beans.factory.support.AbstractBeanDefinition ;
import org.springframework.beans.factory.support.BeanDefinitionBuilder ;
import org.springframework.beans.factory.support.BeanDefinitionBuilder ;
import org.springframework.beans.factory.support.BeanDefinitionRegistry ;
import org.springframework.beans.factory.support.BeanDefinitionRegistry ;
@ -78,7 +79,8 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector {
String prefix = extractPrefix ( type ) ;
String prefix = extractPrefix ( type ) ;
String name = ( StringUtils . hasText ( prefix ) ? prefix + "-" + type . getName ( )
String name = ( StringUtils . hasText ( prefix ) ? prefix + "-" + type . getName ( )
: type . getName ( ) ) ;
: type . getName ( ) ) ;
if ( ! registry . containsBeanDefinition ( name ) ) {
if ( ! containsBeanDefinition (
( ConfigurableListableBeanFactory ) registry , name ) ) {
registerBeanDefinition ( registry , type , name ) ;
registerBeanDefinition ( registry , type , name ) ;
}
}
}
}
@ -119,6 +121,23 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector {
+ " annotation found on '" + type . getName ( ) + "'." ) ;
+ " annotation found on '" + type . getName ( ) + "'." ) ;
}
}
private boolean containsBeanDefinition (
ConfigurableListableBeanFactory beanFactory , String name ) {
boolean result = beanFactory . containsBeanDefinition ( name ) ;
if ( result ) {
return true ;
}
if ( beanFactory
. getParentBeanFactory ( ) instanceof ConfigurableListableBeanFactory ) {
return containsBeanDefinition (
( ConfigurableListableBeanFactory ) beanFactory
. getParentBeanFactory ( ) ,
name ) ;
}
return false ;
}
}
}
}
}