165. The locations of Spring Boot @ConfigurationProperties are outdated [Learn Spring Boot from scratch]

 

【Video & Communication Platform】

à SpringBoot Video 

http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share

à  SpringCloud Video

http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share

à Spring Boot source code 

https://gitee.com/happyangellxq520/spring-boot

à Spring Boot communication platform 

http://412887952-qq-com.iteye.com/blog/2321532

 

Origin of need :

 When recording Spring Boot custom properties, I found that the locations of @ConfigurationProperties are out of date, the following code:

@ConfigurationProperties(prefix="email",locations={"classpath:email.properties"})
public class Email2Properties {
}

 

       In the case of the above code, locations are outdated and are not recommended to be used.

 

Release Notes:

       In the above situation, the premise is that the Spring Boot version uses a version above 1.4+ . If the version before 1.4 is used , such as version 1.3.3 , it can be used normally.

 

Solution:

( 1 ) After @EnableConfigurationPropertiesdeactivating the custom configuration class

( 2 ) The method used @Componentis to register as a component, and then use @PropertySourceit to specify a custom resource directory, as follows:

@Component
@ConfigurationProperties(prefix="email")
@PropertySource(value={"classpath:email.properties"})
public class Email2Properties {
}

 

You can refer to the link: https://github.com/spring-projects/spring-boot/issues/6726

 

 

        

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326682586&siteId=291194637