Rename @ImportConfigurationPropertiesBean

Rename `@ImportConfigurationPropertiesBean` to
`@ConfigurationPropertiesImport`.

Closes gh-23172
This commit is contained in:
Phillip Webb 2020-09-14 19:30:24 -07:00
parent 433b357423
commit c857a743a0
18 changed files with 97 additions and 97 deletions

View File

@ -1227,7 +1227,7 @@ Spring Boot provides infrastructure to bind `@ConfigurationProperties` types and
You can either enable configuration properties on a class-by-class basis or enable configuration property scanning that works in a similar manner to component scanning. You can either enable configuration properties on a class-by-class basis or enable configuration property scanning that works in a similar manner to component scanning.
Sometimes, classes annotated with `@ConfigurationProperties` might not be suitable for scanning, for example, if you're developing your own auto-configuration or you want to enable them conditionally. Sometimes, classes annotated with `@ConfigurationProperties` might not be suitable for scanning, for example, if you're developing your own auto-configuration or you want to enable them conditionally.
In these cases, specify the list of types to process using the `@EnableConfigurationProperties` or `@ImportConfigurationPropertiesBean` annotations. In these cases, specify the list of types to process using the `@EnableConfigurationProperties` or `@ConfigurationPropertiesImport` annotations.
This can be done on any `@Configuration` class, as shown in the following example: This can be done on any `@Configuration` class, as shown in the following example:
[source,java,indent=0] [source,java,indent=0]
@ -1253,7 +1253,7 @@ If you want to define specific packages to scan, you can do so as shown in the f
[NOTE] [NOTE]
==== ====
When the `@ConfigurationProperties` bean is registered using configuration property scanning or via `@EnableConfigurationProperties` or `@ImportConfigurationPropertiesBean`, the bean has a conventional name: `<prefix>-<fqn>`, where `<prefix>` is the environment key prefix specified in the `@ConfigurationProperties` annotation and `<fqn>` is the fully qualified name of the bean. When the `@ConfigurationProperties` bean is registered using configuration property scanning or via `@EnableConfigurationProperties` or `@ConfigurationPropertiesImport`, the bean has a conventional name: `<prefix>-<fqn>`, where `<prefix>` is the environment key prefix specified in the `@ConfigurationProperties` annotation and `<fqn>` is the fully qualified name of the bean.
If the annotation does not provide any prefix, only the fully qualified name of the bean is used. If the annotation does not provide any prefix, only the fully qualified name of the bean is used.
The bean name in the example above is `acme-com.example.AcmeProperties`. The bean name in the example above is `acme-com.example.AcmeProperties`.
@ -1333,18 +1333,18 @@ To configure a bean from the `Environment` properties, add `@ConfigurationProper
Any JavaBean property defined with the `another` prefix is mapped onto that `ExampleItem` bean in manner similar to the preceding `AcmeProperties` example. Any JavaBean property defined with the `another` prefix is mapped onto that `ExampleItem` bean in manner similar to the preceding `AcmeProperties` example.
If you want to use constructor binding with a third-party class, you can't use a `@Bean` method since Spring will need to create the object instance. If you want to use constructor binding with a third-party class, you can't use a `@Bean` method since Spring will need to create the object instance.
For those situations, you can use an `@ImportConfigurationPropertiesBean` annotation on your `@Configuration` or `@SpringBootApplication` class. For those situations, you can use an `@ConfigurationPropertiesImport` annotation on your `@Configuration` or `@SpringBootApplication` class.
[source,java,indent=0] [source,java,indent=0]
---- ----
@SpringBootApplication @SpringBootApplication
@ImportConfigurationPropertiesBean(type = ExampleItem.class, prefix = "another") @ConfigurationPropertiesImport(type = ExampleItem.class, prefix = "another")
public class MyApp { public class MyApp {
... ...
} }
---- ----
TIP: `@ImportConfigurationPropertiesBean` also works for JavaBean bindings as long as the type has a single no-arg constructor TIP: `@ConfigurationPropertiesImport` also works for JavaBean bindings as long as the type has a single no-arg constructor

View File

@ -80,9 +80,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
static final String NAME_ANNOTATION = "org.springframework.boot.context.properties.bind.Name"; static final String NAME_ANNOTATION = "org.springframework.boot.context.properties.bind.Name";
static final String IMPORT_CONFIGURATION_PROPERTIES_BEAN_ANNOATION = "org.springframework.boot.context.properties.ImportConfigurationPropertiesBean"; static final String CONFIGURATION_PROPERTIES_IMPORT_ANNOATION = "org.springframework.boot.context.properties.ConfigurationPropertiesImport";
static final String IMPORT_CONFIGURATION_PROPERTIES_BEANS_ANNOATION = "org.springframework.boot.context.properties.ImportConfigurationPropertiesBeans"; static final String CONFIGURATION_PROPERTIES_IMPORTS_ANNOATION = "org.springframework.boot.context.properties.ConfigurationPropertiesImports";
private static final Set<String> SUPPORTED_OPTIONS = Collections private static final Set<String> SUPPORTED_OPTIONS = Collections
.unmodifiableSet(Collections.singleton(ADDITIONAL_METADATA_LOCATIONS_OPTION)); .unmodifiableSet(Collections.singleton(ADDITIONAL_METADATA_LOCATIONS_OPTION));
@ -125,12 +125,12 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
return NAME_ANNOTATION; return NAME_ANNOTATION;
} }
protected String importConfigurationPropertiesBeanAnnotation() { protected String configurationPropertiesImportAnnotation() {
return IMPORT_CONFIGURATION_PROPERTIES_BEAN_ANNOATION; return CONFIGURATION_PROPERTIES_IMPORT_ANNOATION;
} }
protected String importConfigurationPropertiesBeansAnnotation() { protected String configurationPropertiesImportsAnnotation() {
return IMPORT_CONFIGURATION_PROPERTIES_BEANS_ANNOATION; return CONFIGURATION_PROPERTIES_IMPORTS_ANNOATION;
} }
@Override @Override
@ -151,8 +151,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
this.metadataEnv = new MetadataGenerationEnvironment(env, configurationPropertiesAnnotation(), this.metadataEnv = new MetadataGenerationEnvironment(env, configurationPropertiesAnnotation(),
nestedConfigurationPropertyAnnotation(), deprecatedConfigurationPropertyAnnotation(), nestedConfigurationPropertyAnnotation(), deprecatedConfigurationPropertyAnnotation(),
constructorBindingAnnotation(), defaultValueAnnotation(), endpointAnnotation(), constructorBindingAnnotation(), defaultValueAnnotation(), endpointAnnotation(),
readOperationAnnotation(), nameAnnotation(), importConfigurationPropertiesBeanAnnotation(), readOperationAnnotation(), nameAnnotation(), configurationPropertiesImportAnnotation(),
importConfigurationPropertiesBeansAnnotation()); configurationPropertiesImportsAnnotation());
} }
@Override @Override
@ -160,7 +160,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
this.metadataCollector.processing(roundEnv); this.metadataCollector.processing(roundEnv);
processConfigurationProperties(roundEnv); processConfigurationProperties(roundEnv);
processEndpoint(roundEnv); processEndpoint(roundEnv);
processImportConfigurationPropertiesBean(roundEnv); processConfigurationPropertiesImport(roundEnv);
if (roundEnv.processingOver()) { if (roundEnv.processingOver()) {
try { try {
writeMetaData(); writeMetaData();
@ -188,22 +188,22 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
} }
} }
private void processImportConfigurationPropertiesBean(RoundEnvironment roundEnv) { private void processConfigurationPropertiesImport(RoundEnvironment roundEnv) {
TypeElement importConfigurationPropertiesBeanType = this.metadataEnv TypeElement configurationPropertiesImportType = this.metadataEnv
.getImportConfigurationPropertiesBeanAnnotationElement(); .getConfigurationPropertiesImportAnnotationElement();
TypeElement importConfigurationPropertiesBeansType = this.metadataEnv TypeElement configurationPropertiesImportsType = this.metadataEnv
.getImportConfigurationPropertiesBeansAnnotationElement(); .getConfigurationPropertiesImportsAnnotationElement();
if (importConfigurationPropertiesBeanType == null && importConfigurationPropertiesBeansType == null) { if (configurationPropertiesImportType == null && configurationPropertiesImportsType == null) {
return; return;
} }
Set<Element> elements = new LinkedHashSet<>(); Set<Element> elements = new LinkedHashSet<>();
if (importConfigurationPropertiesBeanType != null) { if (configurationPropertiesImportType != null) {
elements.addAll(roundEnv.getElementsAnnotatedWith(importConfigurationPropertiesBeanType)); elements.addAll(roundEnv.getElementsAnnotatedWith(configurationPropertiesImportType));
} }
if (importConfigurationPropertiesBeansType != null) { if (configurationPropertiesImportsType != null) {
elements.addAll(roundEnv.getElementsAnnotatedWith(importConfigurationPropertiesBeansType)); elements.addAll(roundEnv.getElementsAnnotatedWith(configurationPropertiesImportsType));
} }
elements.forEach(this::processImportConfigurationPropertiesBean); elements.forEach(this::processConfigurationPropertiesImport);
} }
private Map<Element, List<Element>> getElementsAnnotatedOrMetaAnnotatedWith(RoundEnvironment roundEnv, private Map<Element, List<Element>> getElementsAnnotatedOrMetaAnnotatedWith(RoundEnvironment roundEnv,
@ -314,13 +314,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
} }
} }
private void processImportConfigurationPropertiesBean(Element element) { private void processConfigurationPropertiesImport(Element element) {
this.metadataEnv.getImportConfigurationPropertiesBeanAnnotations(element) this.metadataEnv.getConfigurationPropertiesImportAnnotations(element)
.forEach(this::processImportConfigurationPropertiesBean); .forEach(this::processConfigurationPropertiesImport);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void processImportConfigurationPropertiesBean(AnnotationMirror annotation) { private void processConfigurationPropertiesImport(AnnotationMirror annotation) {
String prefix = getPrefix(annotation); String prefix = getPrefix(annotation);
List<TypeMirror> types = (List<TypeMirror>) this.metadataEnv.getAnnotationElementValues(annotation).get("type"); List<TypeMirror> types = (List<TypeMirror>) this.metadataEnv.getAnnotationElementValues(annotation).get("type");
for (TypeMirror type : types) { for (TypeMirror type : types) {

View File

@ -97,15 +97,15 @@ class MetadataGenerationEnvironment {
private final String nameAnnotation; private final String nameAnnotation;
private final String importConfigurationPropertiesBeanAnnotation; private final String configurationPropertiesImportAnnotation;
private final String importConfigurationPropertiesBeansAnnotation; private final String configurationPropertiesImportsAnnotation;
MetadataGenerationEnvironment(ProcessingEnvironment environment, String configurationPropertiesAnnotation, MetadataGenerationEnvironment(ProcessingEnvironment environment, String configurationPropertiesAnnotation,
String nestedConfigurationPropertyAnnotation, String deprecatedConfigurationPropertyAnnotation, String nestedConfigurationPropertyAnnotation, String deprecatedConfigurationPropertyAnnotation,
String constructorBindingAnnotation, String defaultValueAnnotation, String endpointAnnotation, String constructorBindingAnnotation, String defaultValueAnnotation, String endpointAnnotation,
String readOperationAnnotation, String nameAnnotation, String importConfigurationPropertiesBeanAnnotation, String readOperationAnnotation, String nameAnnotation, String configurationPropertiesImportAnnotation,
String importConfigurationPropertiesBeansAnnotation) { String configurationPropertiesImportsAnnotation) {
this.typeUtils = new TypeUtils(environment); this.typeUtils = new TypeUtils(environment);
this.elements = environment.getElementUtils(); this.elements = environment.getElementUtils();
this.messager = environment.getMessager(); this.messager = environment.getMessager();
@ -118,8 +118,8 @@ class MetadataGenerationEnvironment {
this.endpointAnnotation = endpointAnnotation; this.endpointAnnotation = endpointAnnotation;
this.readOperationAnnotation = readOperationAnnotation; this.readOperationAnnotation = readOperationAnnotation;
this.nameAnnotation = nameAnnotation; this.nameAnnotation = nameAnnotation;
this.importConfigurationPropertiesBeanAnnotation = importConfigurationPropertiesBeanAnnotation; this.configurationPropertiesImportAnnotation = configurationPropertiesImportAnnotation;
this.importConfigurationPropertiesBeansAnnotation = importConfigurationPropertiesBeansAnnotation; this.configurationPropertiesImportsAnnotation = configurationPropertiesImportsAnnotation;
} }
private static FieldValuesParser resolveFieldValuesParser(ProcessingEnvironment env) { private static FieldValuesParser resolveFieldValuesParser(ProcessingEnvironment env) {
@ -265,12 +265,12 @@ class MetadataGenerationEnvironment {
return this.elements.getTypeElement(this.configurationPropertiesAnnotation); return this.elements.getTypeElement(this.configurationPropertiesAnnotation);
} }
TypeElement getImportConfigurationPropertiesBeanAnnotationElement() { TypeElement getConfigurationPropertiesImportAnnotationElement() {
return this.elements.getTypeElement(this.importConfigurationPropertiesBeanAnnotation); return this.elements.getTypeElement(this.configurationPropertiesImportAnnotation);
} }
TypeElement getImportConfigurationPropertiesBeansAnnotationElement() { TypeElement getConfigurationPropertiesImportsAnnotationElement() {
return this.elements.getTypeElement(this.importConfigurationPropertiesBeansAnnotation); return this.elements.getTypeElement(this.configurationPropertiesImportsAnnotation);
} }
AnnotationMirror getConfigurationPropertiesAnnotation(Element element) { AnnotationMirror getConfigurationPropertiesAnnotation(Element element) {
@ -297,13 +297,13 @@ class MetadataGenerationEnvironment {
return getAnnotation(element, this.nameAnnotation); return getAnnotation(element, this.nameAnnotation);
} }
List<AnnotationMirror> getImportConfigurationPropertiesBeanAnnotations(Element element) { List<AnnotationMirror> getConfigurationPropertiesImportAnnotations(Element element) {
List<AnnotationMirror> annotations = new ArrayList<>(); List<AnnotationMirror> annotations = new ArrayList<>();
AnnotationMirror importBean = getAnnotation(element, this.importConfigurationPropertiesBeanAnnotation); AnnotationMirror importBean = getAnnotation(element, this.configurationPropertiesImportAnnotation);
if (importBean != null) { if (importBean != null) {
annotations.add(importBean); annotations.add(importBean);
} }
AnnotationMirror importBeans = getAnnotation(element, this.importConfigurationPropertiesBeansAnnotation); AnnotationMirror importBeans = getAnnotation(element, this.configurationPropertiesImportsAnnotation);
if (importBeans != null) { if (importBeans != null) {
AnnotationValue value = importBeans.getElementValues().values().iterator().next(); AnnotationValue value = importBeans.getElementValues().values().iterator().next();
for (Object contained : (List<?>) value.getValue()) { for (Object contained : (List<?>) value.getValue()) {

View File

@ -50,7 +50,7 @@ class PropertyDescriptorResolver {
* factory method}, if any. * factory method}, if any.
* @param type the target type * @param type the target type
* @param fromImport it the type was imported via a * @param fromImport it the type was imported via a
* {@code @ImportConfigurationPropertiesBean} * {@code @ConfigurationPropertiesImport}
* @param factoryMethod the method that triggered the metadata for that {@code type} * @param factoryMethod the method that triggered the metadata for that {@code type}
* or {@code null} * or {@code null}
* @return the candidate properties for metadata generation * @return the candidate properties for metadata generation

View File

@ -20,8 +20,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
import org.springframework.boot.configurationprocessor.metadata.Metadata; import org.springframework.boot.configurationprocessor.metadata.Metadata;
import org.springframework.boot.configurationsample.ImportConfigurationPropertiesBean; import org.springframework.boot.configurationsample.ConfigurationPropertiesImport;
import org.springframework.boot.configurationsample.ImportConfigurationPropertiesBeans; import org.springframework.boot.configurationsample.ConfigurationPropertiesImports;
import org.springframework.boot.configurationsample.importbean.ImportJavaBeanConfigurationPropertiesBean; import org.springframework.boot.configurationsample.importbean.ImportJavaBeanConfigurationPropertiesBean;
import org.springframework.boot.configurationsample.importbean.ImportMultipleTypeConfigurationPropertiesBean; import org.springframework.boot.configurationsample.importbean.ImportMultipleTypeConfigurationPropertiesBean;
import org.springframework.boot.configurationsample.importbean.ImportRepeatedConfigurationPropertiesBean; import org.springframework.boot.configurationsample.importbean.ImportRepeatedConfigurationPropertiesBean;
@ -32,8 +32,8 @@ import org.springframework.boot.configurationsample.importbean.ImportedValueObje
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link ImportConfigurationPropertiesBean} and * Tests for {@link ConfigurationPropertiesImport} and
* {@link ImportConfigurationPropertiesBeans}. * {@link ConfigurationPropertiesImports}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */

View File

@ -40,8 +40,8 @@ class MetadataGenerationEnvironmentFactory implements Function<ProcessingEnviron
TestConfigurationMetadataAnnotationProcessor.ENDPOINT_ANNOTATION, TestConfigurationMetadataAnnotationProcessor.ENDPOINT_ANNOTATION,
TestConfigurationMetadataAnnotationProcessor.READ_OPERATION_ANNOTATION, TestConfigurationMetadataAnnotationProcessor.READ_OPERATION_ANNOTATION,
TestConfigurationMetadataAnnotationProcessor.NAME_ANNOTATION, TestConfigurationMetadataAnnotationProcessor.NAME_ANNOTATION,
TestConfigurationMetadataAnnotationProcessor.IMPORT_CONFIGURATION_PROPERTIES_BEAN_ANNOATION, TestConfigurationMetadataAnnotationProcessor.CONFIGURATION_PROPERTIES_IMPORT_ANNOATION,
TestConfigurationMetadataAnnotationProcessor.IMPORT_CONFIGURATION_PROPERTIES_BEANS_ANNOATION); TestConfigurationMetadataAnnotationProcessor.CONFIGURATION_PROPERTIES_IMPORTS_ANNOATION);
} }
} }

View File

@ -57,9 +57,9 @@ public class TestConfigurationMetadataAnnotationProcessor extends ConfigurationM
public static final String NAME_ANNOTATION = "org.springframework.boot.configurationsample.Name"; public static final String NAME_ANNOTATION = "org.springframework.boot.configurationsample.Name";
public static final String IMPORT_CONFIGURATION_PROPERTIES_BEAN_ANNOATION = "org.springframework.boot.configurationsample.ImportConfigurationPropertiesBean"; public static final String CONFIGURATION_PROPERTIES_IMPORT_ANNOATION = "org.springframework.boot.configurationsample.ConfigurationPropertiesImport";
public static final String IMPORT_CONFIGURATION_PROPERTIES_BEANS_ANNOATION = "org.springframework.boot.configurationsample.ImportConfigurationPropertiesBeans"; public static final String CONFIGURATION_PROPERTIES_IMPORTS_ANNOATION = "org.springframework.boot.configurationsample.ConfigurationPropertiesImports";
private ConfigurationMetadata metadata; private ConfigurationMetadata metadata;
@ -110,13 +110,13 @@ public class TestConfigurationMetadataAnnotationProcessor extends ConfigurationM
} }
@Override @Override
protected String importConfigurationPropertiesBeanAnnotation() { protected String configurationPropertiesImportAnnotation() {
return IMPORT_CONFIGURATION_PROPERTIES_BEAN_ANNOATION; return CONFIGURATION_PROPERTIES_IMPORT_ANNOATION;
} }
@Override @Override
protected String importConfigurationPropertiesBeansAnnotation() { protected String configurationPropertiesImportsAnnotation() {
return IMPORT_CONFIGURATION_PROPERTIES_BEANS_ANNOATION; return CONFIGURATION_PROPERTIES_IMPORTS_ANNOATION;
} }
@Override @Override

View File

@ -26,8 +26,8 @@ import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AliasFor;
/** /**
* Alternative to Spring Boot's {@code ImportConfigurationPropertiesBean} for testing * Alternative to Spring Boot's {@code ConfigurationPropertiesImport} for testing (removes
* (removes the need for a dependency on the real annotation). * the need for a dependency on the real annotation).
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@ -35,8 +35,8 @@ import org.springframework.core.annotation.AliasFor;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@ConfigurationProperties @ConfigurationProperties
@Repeatable(ImportConfigurationPropertiesBeans.class) @Repeatable(ConfigurationPropertiesImports.class)
public @interface ImportConfigurationPropertiesBean { public @interface ConfigurationPropertiesImport {
Class<?>[] type(); Class<?>[] type();

View File

@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Alternative to Spring Boot's {@code ImportConfigurationPropertiesBeans} for testing * Alternative to Spring Boot's {@code ConfigurationPropertiesImports} for testing
* (removes the need for a dependency on the real annotation). * (removes the need for a dependency on the real annotation).
* *
* @author Phillip Webb * @author Phillip Webb
@ -31,8 +31,8 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
public @interface ImportConfigurationPropertiesBeans { public @interface ConfigurationPropertiesImports {
ImportConfigurationPropertiesBean[] value(); ConfigurationPropertiesImport[] value();
} }

View File

@ -16,14 +16,14 @@
package org.springframework.boot.configurationsample.importbean; package org.springframework.boot.configurationsample.importbean;
import org.springframework.boot.configurationsample.ImportConfigurationPropertiesBean; import org.springframework.boot.configurationsample.ConfigurationPropertiesImport;
/** /**
* An import of a java bean. * An import of a java bean.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@ImportConfigurationPropertiesBean(type = ImportedJavaBean.class, prefix = "importbean") @ConfigurationPropertiesImport(type = ImportedJavaBean.class, prefix = "importbean")
public class ImportJavaBeanConfigurationPropertiesBean { public class ImportJavaBeanConfigurationPropertiesBean {
} }

View File

@ -16,14 +16,14 @@
package org.springframework.boot.configurationsample.importbean; package org.springframework.boot.configurationsample.importbean;
import org.springframework.boot.configurationsample.ImportConfigurationPropertiesBean; import org.springframework.boot.configurationsample.ConfigurationPropertiesImport;
/** /**
* An import of a java bean and a value object. * An import of a java bean and a value object.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@ImportConfigurationPropertiesBean(type = { ImportedJavaBean.class, ImportedValueObject.class }, prefix = "importbean") @ConfigurationPropertiesImport(type = { ImportedJavaBean.class, ImportedValueObject.class }, prefix = "importbean")
public class ImportMultipleTypeConfigurationPropertiesBean { public class ImportMultipleTypeConfigurationPropertiesBean {
} }

View File

@ -16,15 +16,15 @@
package org.springframework.boot.configurationsample.importbean; package org.springframework.boot.configurationsample.importbean;
import org.springframework.boot.configurationsample.ImportConfigurationPropertiesBean; import org.springframework.boot.configurationsample.ConfigurationPropertiesImport;
/** /**
* An import of a java bean and a value object. * An import of a java bean and a value object.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@ImportConfigurationPropertiesBean(type = ImportedJavaBean.class, prefix = "jb") @ConfigurationPropertiesImport(type = ImportedJavaBean.class, prefix = "jb")
@ImportConfigurationPropertiesBean(type = ImportedValueObject.class, prefix = "vo") @ConfigurationPropertiesImport(type = ImportedValueObject.class, prefix = "vo")
public class ImportRepeatedConfigurationPropertiesBean { public class ImportRepeatedConfigurationPropertiesBean {
} }

View File

@ -16,14 +16,14 @@
package org.springframework.boot.configurationsample.importbean; package org.springframework.boot.configurationsample.importbean;
import org.springframework.boot.configurationsample.ImportConfigurationPropertiesBean; import org.springframework.boot.configurationsample.ConfigurationPropertiesImport;
/** /**
* An import of a value object. * An import of a value object.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@ImportConfigurationPropertiesBean(type = ImportedValueObject.class, prefix = "importbean") @ConfigurationPropertiesImport(type = ImportedValueObject.class, prefix = "importbean")
public class ImportValueObjectConfigurationPropertiesBean { public class ImportValueObjectConfigurationPropertiesBean {
} }

View File

@ -46,9 +46,9 @@ import org.springframework.core.annotation.AliasFor;
@Documented @Documented
@EnableConfigurationProperties @EnableConfigurationProperties
@ConfigurationProperties @ConfigurationProperties
@Repeatable(ImportConfigurationPropertiesBeans.class) @Repeatable(ConfigurationPropertiesImports.class)
@Import(ImportConfigurationPropertiesBeanRegistrar.class) @Import(ConfigurationPropertiesImportRegistrar.class)
public @interface ImportConfigurationPropertiesBean { public @interface ConfigurationPropertiesImport {
/** /**
* One or more types that should be imported as a bean. * One or more types that should be imported as a bean.

View File

@ -25,34 +25,34 @@ import org.springframework.core.type.AnnotationMetadata;
/** /**
* {@link ImportBeanDefinitionRegistrar} for * {@link ImportBeanDefinitionRegistrar} for
* {@link ImportConfigurationPropertiesBean @ImportConfigurationPropertiesBean}. * {@link ConfigurationPropertiesImport @ConfigurationPropertiesImport}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
class ImportConfigurationPropertiesBeanRegistrar implements ImportBeanDefinitionRegistrar { class ConfigurationPropertiesImportRegistrar implements ImportBeanDefinitionRegistrar {
@Override @Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry,
BeanNameGenerator importBeanNameGenerator) { BeanNameGenerator importBeanNameGenerator) {
ConfigurationPropertiesBeanRegistrar registrar = new ConfigurationPropertiesBeanRegistrar(registry); ConfigurationPropertiesBeanRegistrar registrar = new ConfigurationPropertiesBeanRegistrar(registry);
MergedAnnotations annotations = importingClassMetadata.getAnnotations(); MergedAnnotations annotations = importingClassMetadata.getAnnotations();
registerBeans(registrar, annotations.get(ImportConfigurationPropertiesBeans.class)); registerBeans(registrar, annotations.get(ConfigurationPropertiesImports.class));
registerBean(registrar, annotations.get(ImportConfigurationPropertiesBean.class)); registerBean(registrar, annotations.get(ConfigurationPropertiesImport.class));
} }
private void registerBeans(ConfigurationPropertiesBeanRegistrar registrar, private void registerBeans(ConfigurationPropertiesBeanRegistrar registrar,
MergedAnnotation<ImportConfigurationPropertiesBeans> annotation) { MergedAnnotation<ConfigurationPropertiesImports> annotation) {
if (!annotation.isPresent()) { if (!annotation.isPresent()) {
return; return;
} }
for (MergedAnnotation<ImportConfigurationPropertiesBean> containedAnnotation : annotation for (MergedAnnotation<ConfigurationPropertiesImport> containedAnnotation : annotation
.getAnnotationArray(MergedAnnotation.VALUE, ImportConfigurationPropertiesBean.class)) { .getAnnotationArray(MergedAnnotation.VALUE, ConfigurationPropertiesImport.class)) {
registerBean(registrar, containedAnnotation); registerBean(registrar, containedAnnotation);
} }
} }
private void registerBean(ConfigurationPropertiesBeanRegistrar registrar, private void registerBean(ConfigurationPropertiesBeanRegistrar registrar,
MergedAnnotation<ImportConfigurationPropertiesBean> annotation) { MergedAnnotation<ConfigurationPropertiesImport> annotation) {
if (!annotation.isPresent()) { if (!annotation.isPresent()) {
return; return;
} }

View File

@ -25,24 +25,24 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
/** /**
* Container annotation that aggregates several {@link ImportConfigurationPropertiesBean} * Container annotation that aggregates several {@link ConfigurationPropertiesImport}
* annotations. * annotations.
* *
* @author Phillip Webb * @author Phillip Webb
* @since 2.4.0 * @since 2.4.0
* @see ImportConfigurationPropertiesBean * @see ConfigurationPropertiesImport
*/ */
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@EnableConfigurationProperties @EnableConfigurationProperties
@Import(ImportConfigurationPropertiesBeanRegistrar.class) @Import(ConfigurationPropertiesImportRegistrar.class)
public @interface ImportConfigurationPropertiesBeans { public @interface ConfigurationPropertiesImports {
/** /**
* The contained {@link ImportConfigurationPropertiesBean} annotations. * The contained {@link ConfigurationPropertiesImport} annotations.
* @return the contained annotations * @return the contained annotations
*/ */
ImportConfigurationPropertiesBean[] value(); ConfigurationPropertiesImport[] value();
} }

View File

@ -51,7 +51,7 @@ public @interface EnableConfigurationProperties {
* {@link ConfigurationProperties @ConfigurationProperties} annotated beans with * {@link ConfigurationProperties @ConfigurationProperties} annotated beans with
* Spring. Standard Spring Beans will also be scanned regardless of this value. * Spring. Standard Spring Beans will also be scanned regardless of this value.
* @return {@code @ConfigurationProperties} annotated beans to register * @return {@code @ConfigurationProperties} annotated beans to register
* @see ImportConfigurationPropertiesBean * @see ConfigurationPropertiesImport
*/ */
Class<?>[] value() default {}; Class<?>[] value() default {};

View File

@ -26,11 +26,11 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/** /**
* Tests for {@link ImportConfigurationPropertiesBean}. * Tests for {@link ConfigurationPropertiesImport}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
class ImportConfigurationPropertiesBeanTests { class ConfigurationPropertiesImportTests {
@Test @Test
void importJavaBean() { void importJavaBean() {
@ -86,7 +86,7 @@ class ImportConfigurationPropertiesBeanTests {
} }
@Configuration @Configuration
@ImportConfigurationPropertiesBean(prefix = "test", type = JavaBean.class) @ConfigurationPropertiesImport(prefix = "test", type = JavaBean.class)
static class JavaBeanConfig { static class JavaBeanConfig {
} }
@ -106,7 +106,7 @@ class ImportConfigurationPropertiesBeanTests {
} }
@Configuration @Configuration
@ImportConfigurationPropertiesBean(prefix = "test", type = ValueObject.class) @ConfigurationPropertiesImport(prefix = "test", type = ValueObject.class)
static class ValueObjectConfig { static class ValueObjectConfig {
} }
@ -126,7 +126,7 @@ class ImportConfigurationPropertiesBeanTests {
} }
@Configuration @Configuration
@ImportConfigurationPropertiesBean(prefix = "test", type = MultiConstructorValueObject.class) @ConfigurationPropertiesImport(prefix = "test", type = MultiConstructorValueObject.class)
static class MultiConstructorValueObjectConfig { static class MultiConstructorValueObjectConfig {
} }
@ -145,14 +145,14 @@ class ImportConfigurationPropertiesBeanTests {
} }
@Configuration @Configuration
@ImportConfigurationPropertiesBean(type = { ValueObject.class, JavaBean.class }, prefix = "test") @ConfigurationPropertiesImport(type = { ValueObject.class, JavaBean.class }, prefix = "test")
static class ImportMultipleTypesConfig { static class ImportMultipleTypesConfig {
} }
@Configuration @Configuration
@ImportConfigurationPropertiesBean(type = ValueObject.class, prefix = "vo") @ConfigurationPropertiesImport(type = ValueObject.class, prefix = "vo")
@ImportConfigurationPropertiesBean(type = JavaBean.class, prefix = "jb") @ConfigurationPropertiesImport(type = JavaBean.class, prefix = "jb")
static class ImportRepeatedAnnotationsConfig { static class ImportRepeatedAnnotationsConfig {
} }