Detailed explanation of springboot's annotations

Configuration class related:

@PropertySource(value =  "classpath:test.properties") //We all write configuration files to application.yml. Sometimes we don't want to write the configuration into the application configuration file, then we need to customize the configuration file, such as test.properties:

@ConfigurationProperties(prefix =  "com.forezp") //Prefix in the configuration file, properties are automatically injected

@EnableConfigurationProperties //The @ConfigurationProperties annotation is mainly used to convert the properties configuration file into a bean for use, and the @EnableConfigurationProperties annotation is used to make the @ConfigurationProperties annotation effective. If only the @ConfigurationProperties annotation is configured, the beans converted from the properties configuration file cannot be obtained in the IOC container. Generally, there is no need to add it, because the @ComponentScan and @EnableConfigurationProperties annotations are already included in the @SpringBootApplication annotation of the startup class of our appliacation.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325174597&siteId=291194637