1.在application.yml增加常量

content:basic-url: http://localhost:8088/

2.在可扫描包的门路下增加对于常量的实体

package com.baomidou.ant.demo.entity;import lombok.Data;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.context.annotation.PropertySource;import org.springframework.stereotype.Component;@Data//注册到Spring容器@Component//指定常量资源门路@ConfigurationProperties("content")public class Content {    //创立相应属性    //间接应用注解获取常量值    private String basicUrl;}

3.应用

申明

  @Autowired    private Content content;

应用
String basicURL=content.getBasicUrl();

注意事项:应用时可能会呈现Could not autowire,解决办法如https://segmentfault.com/a/11...