自定义properties文件读取

    1.创建实体类,使用注解自动配置属性:

@Component
@ConfigurationProperties(prefix = "hive.fz") 
@PropertySource(value = "hive-config.properties")

(1)交由spring容器管理

(2)注明Properties文件中的配置项前缀

(3)指明配置文件路径(这样spring就不需要依次匹配了)

2.使用value注解指定:

@Value("${hive.rule}")

${}内为properties配置的全名称,spring会依次从各properties文件中去读取,直到找到位置,也就是使用于自定义中配置的,也使用于application.properties文件中配置的。

猜你喜欢

转载自blog.csdn.net/qq_28060549/article/details/84965056