You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add repeatable `@ImportConfigurationPropertiesBean` annotation that can
be used to import types and treat them as `@ConfigurationProperties`
beans. This annotation is specifically designed to support third-party
classes that can't contain any Spring annotations.
Closesgh-23172
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc
+18-4Lines changed: 18 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1227,7 +1227,7 @@ Spring Boot provides infrastructure to bind `@ConfigurationProperties` types and
1227
1227
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.
1228
1228
1229
1229
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.
1230
-
In these cases, specify the list of types to process using the `@EnableConfigurationProperties` annotation.
1230
+
In these cases, specify the list of types to process using the `@EnableConfigurationProperties` or `@ImportConfigurationPropertiesBean` annotations.
1231
1231
This can be done on any `@Configuration` class, as shown in the following example:
1232
1232
1233
1233
[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
1253
1253
1254
1254
[NOTE]
1255
1255
====
1256
-
When the `@ConfigurationProperties` bean is registered using configuration property scanning or via `@EnableConfigurationProperties`, 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.
1256
+
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.
1257
1257
If the annotation does not provide any prefix, only the fully qualified name of the bean is used.
1258
1258
1259
1259
The bean name in the example above is `acme-com.example.AcmeProperties`.
@@ -1325,12 +1325,26 @@ To configure a bean from the `Environment` properties, add `@ConfigurationProper
1325
1325
----
1326
1326
@ConfigurationProperties(prefix = "another")
1327
1327
@Bean
1328
-
public AnotherComponent anotherComponent() {
1328
+
public ExampleItem exampleItem() {
1329
1329
...
1330
1330
}
1331
1331
----
1332
1332
1333
-
Any JavaBean property defined with the `another` prefix is mapped onto that `AnotherComponent` bean in manner similar to the preceding `AcmeProperties` example.
1333
+
Any JavaBean property defined with the `another` prefix is mapped onto that `ExampleItem` bean in manner similar to the preceding `AcmeProperties` example.
1334
+
1335
+
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.
1336
+
For those situations, you can use an `@ImportConfigurationPropertiesBean` annotation on your `@Configuration` or `@SpringBootApplication` class.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataGenerationEnvironment.java
+32-1Lines changed: 32 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -97,10 +97,15 @@ class MetadataGenerationEnvironment {
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java
+18-6Lines changed: 18 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -49,16 +49,19 @@ class PropertyDescriptorResolver {
49
49
* specified {@link TypeElement type} based on the specified {@link ExecutableElement
50
50
* factory method}, if any.
51
51
* @param type the target type
52
+
* @param fromImport it the type was imported via a
53
+
* {@code @ImportConfigurationPropertiesBean}
52
54
* @param factoryMethod the method that triggered the metadata for that {@code type}
53
55
* or {@code null}
54
56
* @return the candidate properties for metadata generation
0 commit comments