摘要:
主要使用的注解类 @PropertySource, @EnableConfigurationProperties, @ConfigurationProperties
- 属性值:prefix/value, 代表属性文件中的key前缀,即公共部分。如:
@ConfigurationProperties("mq.config-prefix")
- classpath: 即jar包内的文件路径;如
classpath:config/testconfig.properties
- path:jar同级目录下文件路径;如
path:config/testconfig.properties
- 指定那些类是需要自动装配在配置类中
备注如下
- 属性文件中key格式,支持<横杠-> <下划线_> < 驼峰命名>. 如下
config.properties
, javaBean中属性的命名一律驼峰命名
mq.queue_config.month-queue=month
mq.queue-config.yearQueue=year
mq.queueConfig.exchangeName=fanout-exchange
@ConfigurationProperties
中的prefix
,如果属性文件中如上形式,那么prefix必须用-连接,即@ConfigurationProperties(prefix = "mq.queue-config")
附上官网链接 link.