@ConfigurationProperties Spring Boot Configuration Annotation Processor not found in classpath

前端 未结 13 1078
太阳男子
太阳男子 2021-02-02 05:06

I try to make completion for custom properties in Spring Boot.

I tried to create a simple project via IntelliJ IDEA 2016.3:

  1. Created a new G
13条回答
  •  不知归路
    2021-02-02 05:37

    You have to mention in the main class the class you want to use @ConfigurationProperties annotation like below.

    @EnableConfigurationProperties(AppProperties.class)
    

    The Property Configuration class with @ConfigurationProperties will be like this

    import org.springframework.boot.context.properties.ConfigurationProperties;
    
    
    @ConfigurationProperties(prefix = "app")
    public class AppProperties {
        String name;
        String id;
    }
    
    
    

    The Main class will be like this

    import com.auth2.demo.config.AppProperties;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    
    @SpringBootApplication
    @EnableConfigurationProperties(AppProperties.class)
    public class DemoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    
    }
    
    

提交回复
热议问题