@Value("${xxxx}")注解的配置及使用

代码中的用法

Spring 通过@Value注解获取*.porperties文件code的内容,然后赋值给使用该注解的Code属性上。

@Value("${code}")
private String Code;

看一下这个resource.properties文件(resource为文件名称)

code=002

spring中的配置

<context:property-placeholder location="classpath:resources/resource.properties" />

该文件的引入有三中实现方式,如上提供最简单,最常用的一种方式提供参考。

原文地址:https://www.cnblogs.com/niceyoo/p/8734225.html