zoukankan      html  css  js  c++  java
  • springboot读取application.properties中自定义配置

    假设在application-xxx.properties中配置

    user.name=yuhk

    一、在Controller中读取

    @Value("{$user.name}")

    private String userName;

    二、static属性读取

    首先,要给类加上@Component注解

    然后,在属性的set方法上加入@Value注解

    例:

    @Component
    public class Hi {
      public static String userName;
      @Value("${user.name}")
      public String setUserName(String name) {
        this.userName = name;
      }
    }
  • 相关阅读:
    【leetcode】对称二叉树
    【leetcode】判断回文数
    053686
    053685
    053684
    053683
    053682
    053681
    053680
    053477
  • 原文地址:https://www.cnblogs.com/punkrocker/p/10632395.html
Copyright © 2011-2022 走看看