spring boot使用配置文件设置常量字段

  1. 新闻资讯
  2. 技术百科
公司新闻 案例分享 技术百科 行业动态

spring boot使用配置文件设置常量字段

来源:奇站网络 浏览量:1965 发布日期: 2020-10-19

将配置项读取到字段上

  1. @Configuration
  2. @Getter
  3. @Setter
  4. public class PropertiesConfig {
  5. @Value("${qizhan.root}")
  6. private String root;
  7. @Value("${qizhan.path}")
  8. private String path;
  9. }

将配置类自动注入

  1. @Slf4j
  2. @Component
  3. public class PropertiesHelper {
  4. @Autowired
  5. public void init(PropertiesConfig config) {
  6. WebConstants.WEB_ROOT = config.getRoot();
  7. WebConstants.PATH = config.getPath();
  8. log.info(WebConstants.WEB_ROOT);
  9. }
  10. }
标签: #spring boot

厦门奇站网络科技有限公司

电话:13313868605

QQ:3413772931

地址:厦门集美区软件园三期

网站地图


                    扫一扫加我咨询