您的位置:首页 > 编程语言 > Java开发

SpringMVC通过@Value注解读取.properties配置

2016-10-07 22:54 369 查看

SpringMVC通过@Value注解读取.properties配置

在bean(可以是controller、service、dao等)中,使用@Value注解:

public class TestService{
@Value("${sytem.username}")
String loginUserName;
}

在spring中定义资源文件:

<!-- 导入属性配置文件 -->
<context:property-placeholder location="classpath:properties/*.properties" ignore-unresolvable="true" />
config.properties文件:

sytem.username=admin

这样config.properties中的sytem.username就注入到loginUserName属性中了。

原文链接:http://www.itdadao.com/articles/c15a352661p0.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring mvc java maven