Skip to content

Commit

Permalink
Revise usage of @EnableConfigurationProperties
Browse files Browse the repository at this point in the history
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 <zhouyanming@gmail.com>
  • Loading branch information
quaff committed Feb 6, 2025
1 parent 2904285 commit 9e42b1b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -29,14 +29,9 @@
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.cloud.util.enabled", matchIfMissing = true)
@AutoConfigureOrder(0)
@EnableConfigurationProperties
@EnableConfigurationProperties(InetUtilsProperties.class)
public class UtilAutoConfiguration {

@Bean
public InetUtilsProperties inetUtilsProperties() {
return new InetUtilsProperties();
}

@Bean
@ConditionalOnMissingBean
public InetUtils inetUtils(InetUtilsProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand All @@ -25,7 +25,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -85,7 +84,6 @@ HasFeatures localFeatures() {
}

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
public static class Config {

@Autowired(required = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand All @@ -26,7 +26,6 @@
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
import org.springframework.cloud.client.discovery.DiscoveryClient;
Expand Down Expand Up @@ -80,7 +79,6 @@ private Status assertHealth(Health health, Status expected) {
}

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
public static class Config {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand All @@ -20,7 +20,6 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ConfigurableApplicationContext;
Expand All @@ -37,7 +36,6 @@
*/
@Order(0)
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
public class TestBootstrapConfiguration {

public static List<String> fooSightings = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -29,7 +29,6 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.cloud.bootstrap.BootstrapApplicationListener;
Expand Down Expand Up @@ -741,7 +740,6 @@ void activeAndIncludeProfileFromBootstrapPropertySource_WhenMultiplePlacesHaveAc
}

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
protected static class BareConfiguration {

}
Expand Down

0 comments on commit 9e42b1b

Please sign in to comment.