@ConfigurationProperties用于将主配置文件(application.properties或者“application.yml”)中的属性,映射到实体类中对应的属性。意思就是把主配置文件中配置属性设置到对应的Bean属性上。只需要写明prefix,如下,prefix是sever,就会自动将application文件中以sever开头的配置一一注入到对应的属性中去,比如配置文件的sever.port=8080会注入到类中的port属性。
@PropertySource则是指定某一路径的配置文件加载,配合@value注解将其映射到实体类中对应的属性,如下,指定类路径的下hellword.properties文件,将其my.name配置注入类中的name属性。
@Configuration @PropertySource("classpath:hellword.properties") public class HelloWorldConfig { @Value(${my.name}) private String name; }
- ConfigurationProperties PropertySource SpringBootconfigurationproperties propertysource springboot configurationproperties注解springboot propertysource springboot properties 注解propertysource springboot configurationproperties springboot方式 文件 configurationproperties乱码quot springboot propertysource configurationproperties 注解propertysource spring6 spring configurationproperties动态apollo问题