在java类文件中使用 PropertySource 注解:
@PropertySource(value={"classpath:jdbc.properties"})
public class ReadProperties {
@Value(value="${jdbc.username}")
private String username;
}
用法示例: 在spring.xml配置文件中添加标签
代码如下:
<context:property-placeholder ignore-unresolvable="true" location="classpath:redis-key.properties"/>
在 spring.xml 中使用配置文件属性:
<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
在java文件中使用:
@Value("${jdbc_url}")
ivate String jdbcUrl; // 注意:这里变量不能定义成static