SoFunction
Updated on 2025-04-05

About @ConfigurationProperties annotation full analysis

@ConfigurationProperties annotation analysis

@ConfigurationProperties annotation is similar to @value. You can map configurations in the application to java variables. With @ConfigurationProperties, you can configure whether to load beans.

Example

spring: 
  complex:   #Is the heavyweight mode enabled? The development environment bean can be loaded online without loading    enable: true

ConfigProperties The identifier of whether to load is loaded. Load as true

Not loaded as fasle corresponding to the above configuration

@ConfigurationProperties(prefix = "")
public class ConfigProperties {

    private boolean enable;

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
         = enable;
    }
}

Specify the above configured identity via @EnableConfigurationProperties

And judged by @ConditionalOnProperty The following implementation

If the application is configured with false or not (default is false), the swagger-related configuration will not be loaded and improve the startup speed

@Configuration(proxyBeanMethods = false)
@EnableSwagger2
@EnableConfigurationProperties()
@ConditionalOnProperty(prefix = "", name = "enable", havingValue = "true", matchIfMissing = false) Specify the attribute judgment Iftrue Load Default isfalse
public class SwaggerConfig{


}

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.