设为首页 加入收藏

TOP

Spring 3中新增的@value注解
2014-11-24 14:51:42 来源: 作者: 【 】 浏览:39
Tags:Spring 新增 @value 注解

在spring 3.0中,可以通过使用@value,对一些如xxx.properties文件
中的文件,进行键值对的注入,例子如下:


1 首先在applicationContext.xml中加入:
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">


的命名空间,然后


2


3 创建test.properties
abc=123


4
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/admin/images")
@Controller
public class ImageAdminController {

private String imageDir;
@Value("#{settings['test.abc']}")
public void setImageDir(String val) {
this.imageDir = val;
}


}


这样就将test.abc的值注入了imageDir中了。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇介绍HTML 5的datalist 下一篇Struts2的零配置和REST插件

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: