Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9e42b1b

Browse files
committedFeb 6, 2025·
Revise usage of @EnableConfigurationProperties
1. use `@EnableConfigurationProperties` to register configuration properties beans if the bean name is not relevant. 2. remove `@EnableConfigurationProperties` without specified value if the `@Configuration` class doesn't contain any `@ConfigurationProperties` bean. Signed-off-by: Yanming Zhou <[email protected]>
1 parent 2904285 commit 9e42b1b

File tree

5 files changed

+6
-19
lines changed

5 files changed

+6
-19
lines changed
 

‎spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/UtilAutoConfiguration.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,14 +29,9 @@
2929
@Configuration(proxyBeanMethods = false)
3030
@ConditionalOnProperty(value = "spring.cloud.util.enabled", matchIfMissing = true)
3131
@AutoConfigureOrder(0)
32-
@EnableConfigurationProperties
32+
@EnableConfigurationProperties(InetUtilsProperties.class)
3333
public class UtilAutoConfiguration {
3434

35-
@Bean
36-
public InetUtilsProperties inetUtilsProperties() {
37-
return new InetUtilsProperties();
38-
}
39-
4035
@Bean
4136
@ConditionalOnMissingBean
4237
public InetUtils inetUtils(InetUtilsProperties properties) {

‎spring-cloud-commons/src/test/java/org/springframework/cloud/client/actuator/FeaturesEndpointTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525

2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
28-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2928
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3029
import org.springframework.context.annotation.Bean;
3130
import org.springframework.context.annotation.Configuration;
@@ -85,7 +84,6 @@ HasFeatures localFeatures() {
8584
}
8685

8786
@Configuration(proxyBeanMethods = false)
88-
@EnableConfigurationProperties
8987
public static class Config {
9088

9189
@Autowired(required = false)

‎spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/health/DiscoveryClientHealthIndicatorTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import org.springframework.boot.actuate.health.HealthContributor;
2727
import org.springframework.boot.actuate.health.HealthIndicator;
2828
import org.springframework.boot.actuate.health.Status;
29-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3029
import org.springframework.boot.test.context.SpringBootTest;
3130
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
3231
import org.springframework.cloud.client.discovery.DiscoveryClient;
@@ -80,7 +79,6 @@ private Status assertHealth(Health health, Status expected) {
8079
}
8180

8281
@Configuration(proxyBeanMethods = false)
83-
@EnableConfigurationProperties
8482
public static class Config {
8583

8684
@Bean

‎spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/TestBootstrapConfiguration.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.List;
2121

2222
import org.springframework.beans.factory.annotation.Qualifier;
23-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2423
import org.springframework.context.ApplicationContextInitializer;
2524
import org.springframework.context.ApplicationEventPublisher;
2625
import org.springframework.context.ConfigurableApplicationContext;
@@ -37,7 +36,6 @@
3736
*/
3837
@Order(0)
3938
@Configuration(proxyBeanMethods = false)
40-
@EnableConfigurationProperties
4139
public class TestBootstrapConfiguration {
4240

4341
public static List<String> fooSightings = null;

‎spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@
2929
import org.springframework.boot.WebApplicationType;
3030
import org.springframework.boot.builder.SpringApplicationBuilder;
3131
import org.springframework.boot.context.properties.ConfigurationProperties;
32-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3332
import org.springframework.boot.context.properties.bind.Bindable;
3433
import org.springframework.boot.context.properties.bind.Binder;
3534
import org.springframework.cloud.bootstrap.BootstrapApplicationListener;
@@ -741,7 +740,6 @@ void activeAndIncludeProfileFromBootstrapPropertySource_WhenMultiplePlacesHaveAc
741740
}
742741

743742
@Configuration(proxyBeanMethods = false)
744-
@EnableConfigurationProperties
745743
protected static class BareConfiguration {
746744

747745
}

0 commit comments

Comments
 (0)
Please sign in to comment.