SpringBoot使用自定义的配置文件

怎么用

  1. 新建自定义的配置文件,并且在自定义的配置文件中输入内容

    

 

 

  1. 新建配置类,并且使用注解component,ConfigurationProperties(prefix为配置文件中的前缀),PropertySource

@Component
@ConfigurationProperties(prefix = "jb")
@PropertySource("classpath:/config.properties")
@Data
public class ConfigProperties {
    private String officialUrl;
    private String testUrl;
}

3、在要使用的地方@Autowired注入即可

posted @ 2021-08-10 13:39  时间外的往事  阅读(311)  评论(0)    收藏  举报