一次@value取值失败的原因
网上down了一份源码。启动后报错,通过报错信息定位到这个地方:
之前对这个@Value的实现方式我也没了解过,所以乘机对springboot关于这一块的源码研究了一下。可以参考当时我的一篇分析记录《@value》。对@value的原理又了一定的了解之后,发现问题并没有处在解析这一块,而是springboot并没有读取我们的配置文件。配置文件有两个:
那么为什么没有读去呢?然后我又分析了一下源码,发现默认情况下,只会读去默认的配置文件路径名称。分别是:
(1) 使用@PropertySource注解
直接在启动类上使用@PropertySource注解来加载不同的配置文件,具体如下所示:
(2) 修改spring.profiles.active属性
需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值,如:spring.profiles.active=dev就会加载application-dev.properties配置文件内容,具体如下所示:
(3) 执行命令行
如上面介绍所讲的一样,我们可以使用命令行,比如执行java -jar xxx.jar --spring.profiles.active=test,可以观察到服务端口被设置为8082,也就是测试环境的配置(test)。
一次@value取值失败的原因的更多相关文章
- react 在IE9下input标签使用e.target.value取值失败
在react项目开发中,input标签使用onChange方法获取输入值改变state: <input type="text" id="redeemNum" ...
- 使用spring中4.2.6版本使用@Value取值失败,结果为${xxx}的情况
环境:spring 4.2.6 使用全注解来获取值的时候发生@Value为写好的表达式 简单的代码: 实体类: public class RichMan { @Value(value=" ...
- php上传$_FILES 无法取值
无法取值的主要原因在form. 代码 <form method="post" action="****" name="theForm" ...
- 页面传递的都是string ; 每个标签要有name的原因是为了取值 因为传递给后台是键值对的形式
页面传递的都是string ; 每个标签要有name的原因是为了取值 因为传递给后台是键值对的形式
- Spring @Value取值为null或@Autowired注入失败
@Value 用于注入.properties文件中定义的内容 @Autowired 用于装配bean 用法都很简单,很直接,但是稍不注意就会出错.下面就来说说我遇到的问题. 前两天在项目中遇到了一个问 ...
- loadrunner动态从mysql取值
loadrunner动态从mysql取值 [需要下载跟数据库服务器一致的dll,32位或64位] loadrunner中有参数化从数据库中取值,但是只是静态的,对于一些要实时取值的数据就game ov ...
- cin 对象取值过程详解
突然又空,鉴于对cin对象的去值机制还不是很了解,就探究一番,并且记下来,方便以后复习. #include <iostream> int main(void) { using namesp ...
- sqlserver 导入数据出现 无法创建 OLE DB 取值函数。请查看列元数据是否有效
我用的是Sql Server 的导入导出功能来实现的,但是有些数据可以导进去,有些就不行.总是出现一些错误! 执行之前 (错误)消息错误 0xc0202005: 数据流任务: 在数据源中找不到列“Un ...
- mybatis映射文件参数处理 #{}取值与${}取值的区别
#{}:是以预编译的映射,将参数设置到sql语句中,和jdbc的preraredStatement一样,使用占位符,防止sql注入. ${}:取出的值会直接拼装在sql中,会有安全问题. 大多数情况下 ...
随机推荐
- python基础===文件对象的访问模式,以及计数循环的使用方法
案例一: 一个几M的文本文件,需要每隔100行写到新的文件中. 代码实现如下: with open(r'f:\book.txt','rb') as f1: with open(r'f:\book2.t ...
- Github上的几个C++开源项目
Github上的几个C++开源项目 http://blog.csdn.net/fyifei0558/article/details/47001677 http://www.zhihu.com/ques ...
- Python标准库——collections模块的Counter类
1.collections模块 collections模块自Python 2.4版本开始被引入,包含了dict.set.list.tuple以外的一些特殊的容器类型,分别是: OrderedDict类 ...
- Oracle基础 05 联机日志 redolog
--两个相关视图v$logv$logfile alter system switch logfile; --强制日志切换alter system checkpoint; --强制检查点 - ...
- RESTful 接口实现简明指南
REST 简介 REST 是一个术语的缩写,REpresentational State Transfer,中文直译「表征状态转移」,这是个很拗口的词.我的建议是先不要强行理解,直接看怎么做,等对实施 ...
- #6034. 「雅礼集训 2017 Day2」线段游戏 李超树
#6034. 「雅礼集训 2017 Day2」线段游戏 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统 ...
- 2016noipday1t1玩具迷题结题报告
经常读这个代码有益于比赛时想起一些思路.... day1t1,洛谷dalao称之为水题...??然后我去年还是没拿到分,就这个,我还就写了40%的数据,AC到40,然而这不是关键,注释了freopen ...
- 2、Flask实战第2天:URL传参
当我们访问网站/的时候,会执行hell_world函数,并把这个函数的返回值返回给浏览器,这样浏览器就显示hello world了 @app.route('/') def hello_world(): ...
- centos7下ip转发的配置
1.先确认ipv4配置了转发设置 vim /etc/sysctl.conf #命令1(编辑配置文件) net.ipv4.ip_forward=1 ...
- 线程同步CriticalSection
孙鑫 第十五/十六课之四 线程同步CriticalSection 说明 在使用多线程时,一般很少有多个线程完全独立的工作.往往是多个线程同时操作一个全局变量来获取程序的运行结果.多个线程同时访问同一个 ...