解决Sping 框架 Controller@Value获取不到值
原因:要获取 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获取不到值的更多相关文章
- 使用layui框架的select获取选中的值
在使用时需要注意:select标签的外层需要加上类名".layui-form" 接下来就是根据需求来改变下拉框的内容了,直接给select的option重新赋一次值,记得加上对应的 ...
- SSH 框架controller向jsp传递List jsp中使用el表达式获取
mvc可以使用ModelAndViev传递数据选择跳转的视图 controller中的代码, 把一个模拟的表单studentListSimulate传给ModelAndView @RequestMap ...
- Spring mvc框架 controller间跳转 ,重定向 ,传参
一.需求背景 1. 需求:spring MVC框架controller间跳转,需重定向.有几种情况:不带参数跳转,带参数拼接url形式跳转,带参数不拼接参数跳转,页面也能显示. @Req ...
- Sping框架的IOC特性 悲观锁、乐观锁 Spring的AOP特性
Sping框架的IOC特性 IOC(Inversion of Control):控制反转 以下以课程与老师的安排来介绍控制反转. 一个合理的课程编排系统应该围绕培训的内容为核心,而不应该以具体的培训老 ...
- springboot配置文件(.yml)中自定义属性值并在controller里面获取
1,由于项目需要,学习了新的框架--springboot,顺便练习一下在.yml中配置自定义属性并在controller里面获取.(以下的Springboot框架我已经搭建好,就不在陈述) 2,spr ...
- 解决CI框架的Disallowed Key Characters错误提示
用CI框架时,有时候会遇到这么一个问题,打开网页,只显示 Disallowed Key Characters 错误提示.有人说 url 里有非法字符.但是确定 url 是纯英文的,问题还是出来了.但清 ...
- 如何解决谷歌浏览器下jquery无法获取图片的尺寸
代码如下: $(document).ready(function(){ var img_h=$img.height(); var img_w=$img.width(); }) 以上代码在IE和火狐中没 ...
- spring mvc controller中获取request head内容
spring mvc controller中获取request head内容: @RequestMapping("/{mlid}/{ptn}/{name}") public Str ...
- spring mvc在Controller中获取ApplicationContext
spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...
随机推荐
- High-current supply uses standard three-terminal regulator
Voltage-regulator design for high output currents can be a critical and difficult task. Although vol ...
- 对 dpif_class 结构体的一点认识
类 dpif_class 抽象的是OVS交换机用户空间和内核层datapath的通信接口(通过netlink),分层是出于性能和生产效率的考虑,通过接口dpif_class,用户层ovs-v ...
- python笔记6-%u60A0和\u60a0类似unicode解码
前言 有时候从接口的返回值里面获取到的是类似"%u4E0A%u6D77%u60A0%u60A0"这种格式的编码,不是python里面的unicode编码. python里面的uni ...
- combogrid获取多个字段的方法
var g = $('#cc').combogrid('grid'); // 获取表格控件对象var r = g.datagrid('getSelected'); //获取表格当前选中行alert(r ...
- U盘安装Centos7.0图解
用U盘安装Centos7.0 工具/原料 centos 7.0 64位系统:CentOS-7.0-1406-x86_64-DVD.iso ultraiso 一个至少8G的U盘 方法/步骤 1 1.先使 ...
- iOS开源项目:JSONKit
一个Json解析库,其特点是代码简单,只有一个.h和.m文件. https://github.com/johnezang/JSONKit JSON(JavaScript Object Notation ...
- Navicat工具里的empty table和truncate table的区别
如图: 相同点:都会清空数据表里的所有数据 不同点:empty table是清空表里的数据:truncate table是删除表,然后再创建这张表 意义:对于主索引自动增加的情况,empty清表后,新 ...
- linux、mac的bash和zsh如何切换
1.hostname 192-23-2-2 修改主机名字 2.chsh -s /bin/bash和chsh -s /bin/zsh可以永久切换,也就是一登录进来的就是相应的界面 bash/zsh命令是 ...
- Jni的Jclass JmethodID JfrieldID的差异
Jni的Jclass JmethodID JfrieldID 这三者都是java类别的属性,本质上都是指标(Pointer).透过这些指标就能快速调用java类别的函数,或存取对象的属性值.在该类别被 ...
- sqlmap使用帮助文档(1)
当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数 2.判断可以用那种SQL注入技术来注入 3.识别出哪种数据库 4.根据用户选择,读取哪些数据 sqlmap支持五种不同的注入模式: ...