天天看点

@Value的几种常用用法

        //常量

    @Value("#{1}")

    private int constant;

    //从属性源取值

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

    private String name;

    //从属性源取值

    @Value("${test.name2: defaultname}")

    private String namedefault;

    //从容器中获取bean的的属性值

    @Value("#{developerProperty.name}")

    private String dname;

    //从指定属性源获取属性值(jvm属性)

    @Value("#{systemProperties['spring.application.json']}")

    private String systemPropertiesjson;

    //从指定属性源获取属性值(系统环境属性源)

    @Value("#{systemEnvironment['HOME']}")

    private String systemEnvironmentHOME;

    //从指定属性源获取属性值 默认值

    @Value("#{systemEnvironment['HOME22']?:'default'}")

    private String systemEnvironmentHOMEdefault;

    //获取随机值

    @Value("${random.int.5,100;}")

    private Integer randomint;

继续阅读