原因:要获取 int.properties 中的数据 但是 一直拿不到值 如下代码

使用这种方式注入 *.properties文件

<!-- 引入配置文件 -->
<context:property-placeholder location="classpath:*.properties"/>
@RestController
public class HomeController { @Value("${datasource.username}")
private String userName; @RequestMapping(value = "/")
public HashMap<String, String> home() {
HashMap<String, String> hashMap = Maps.newHashMap();
hashMap.put("db_username",userName);
return hashMap;
}
}

解决方法:

@RestController
@PropertySource("classpath:ini.properties")
public class HomeController { @Value("${datasource.username}")
private String userName; @RequestMapping(value = "/")
public HashMap<String, String> home() {
HashMap<String, String> hashMap = Maps.newHashMap();
hashMap.put("db_username",userName);
return hashMap;
}
}

指定读取字段的文件

解决Sping 框架 Controller@Value获取不到值的更多相关文章

  1. 使用layui框架的select获取选中的值

    在使用时需要注意:select标签的外层需要加上类名".layui-form" 接下来就是根据需求来改变下拉框的内容了,直接给select的option重新赋一次值,记得加上对应的 ...

  2. SSH 框架controller向jsp传递List jsp中使用el表达式获取

    mvc可以使用ModelAndViev传递数据选择跳转的视图 controller中的代码, 把一个模拟的表单studentListSimulate传给ModelAndView @RequestMap ...

  3. Spring mvc框架 controller间跳转 ,重定向 ,传参

     一.需求背景     1. 需求:spring MVC框架controller间跳转,需重定向.有几种情况:不带参数跳转,带参数拼接url形式跳转,带参数不拼接参数跳转,页面也能显示.   @Req ...

  4. Sping框架的IOC特性 悲观锁、乐观锁 Spring的AOP特性

    Sping框架的IOC特性 IOC(Inversion of Control):控制反转 以下以课程与老师的安排来介绍控制反转. 一个合理的课程编排系统应该围绕培训的内容为核心,而不应该以具体的培训老 ...

  5. springboot配置文件(.yml)中自定义属性值并在controller里面获取

    1,由于项目需要,学习了新的框架--springboot,顺便练习一下在.yml中配置自定义属性并在controller里面获取.(以下的Springboot框架我已经搭建好,就不在陈述) 2,spr ...

  6. 解决CI框架的Disallowed Key Characters错误提示

    用CI框架时,有时候会遇到这么一个问题,打开网页,只显示 Disallowed Key Characters 错误提示.有人说 url 里有非法字符.但是确定 url 是纯英文的,问题还是出来了.但清 ...

  7. 如何解决谷歌浏览器下jquery无法获取图片的尺寸

    代码如下: $(document).ready(function(){ var img_h=$img.height(); var img_w=$img.width(); }) 以上代码在IE和火狐中没 ...

  8. spring mvc controller中获取request head内容

    spring mvc controller中获取request head内容: @RequestMapping("/{mlid}/{ptn}/{name}") public Str ...

  9. spring mvc在Controller中获取ApplicationContext

    spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...

随机推荐

  1. When to use static method in a java class

    First , please understand its feature : * no need to instantiate a instance, i.e. simply you can jus ...

  2. ExtJS表格——行号、复选框、选择模型

    本篇的内容是为表格添加行号,和复选框,最后谈一下Ext的选择模型.内容比较简单,就直接上代码了.一. 设置行号   行号的设置主要问题在于删除某一行后需要重新计算行号  Ext.onReady(fun ...

  3. (转)Ext.Button点击事件的三种写法

    转自:http://maidini.blog.163.com/blog/static/377627042008111061844345/ ExtJs的写法太灵活了,现在收集了关于Button点击事件的 ...

  4. CMOS DACs act as digitally controlled voltage dividers

    Digital potentiometers, such as Analog Devices’ AD5160, make excellent digitally controlled voltage ...

  5. Retrieving ST-Link/V2 Firmware from Update Utility

    http://www.taylorkillian.com/2013/01/retrieving-st-linkv2-firmware-from.html http://forum.easyelectr ...

  6. fdopen()和fileno()函数

    转:http://book.2cto.com/201212/11763.html 文件描述字函数是流函数的初等函数,每一个流都与一个描述字相连.给定一个打开的文件描述字,可以用fdopen()函数为它 ...

  7. [Gradle] Gradle 构建 android 应用常见问题解决指南

    转载地址:http://www.cnblogs.com/youxilua/p/3348162.html 1: 使用最新的gradle android插件 以前我们写的时候会这么写 dependenci ...

  8. 【转载】惠新宸:PHP在百度的应用现状及展望

    http://blog.sina.com.cn/s/blog_645f8e970100qvd8.html 惠新宸,百度PHP高级顾问,年二十有八,好追根究底,有不良嗜好, 幸性本善.乙酉年识互联网,丁 ...

  9. hello--GAN

    GAN系列学习(1)——前生今世 DCGAN.WGAN.WGAN-GP.LSGAN.BEGAN原理总结及对比 [Learning Notes]变分自编码器(Variational Auto-Encod ...

  10. hdu5297 Y sequence(容斥原理+迭代)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5297 题意:给定整数n和整数r,在1.2.3.4.5.......的序列中删掉能够开2次方的数,3次方的数 ...