如何在springboot中读取自己创建的.properties配置的值

在实体类里面加上

@PropertySource("classpath:/robot_config.properties")
robot_config.properties  // 配置文件的名字

文件放在resources 目录下

类里面的属性取值

  @Value("${quest_mode}")
    private  String questMode;

properties 里面的属性

questMode = /ossServer // 这种格式

 在代码里使用,直接注入就可以了

    @Resource
    private RobotConfig robotConfig;

然后直接使用这个对象,在配置文件里面的值就会赋值上去了。

原文地址:https://www.cnblogs.com/luffyxin/p/11323750.html