前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring3中用注解直接注入properties中的值

Spring3中用注解直接注入properties中的值

作者头像
明明如月学长
发布2021-08-27 15:05:21
4320
发布2021-08-27 15:05:21
举报

转自:http://sunjun041640.blog.163.com/blog/static/256268322013112325324373/

在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中了

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015/10/17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档