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

来源:互联网 发布:淘宝导航三级分类代码 编辑:程序博客网 时间:2024/05/14 11:16

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

@Servicepublic 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属性中了。

1 0
原创粉丝点击