spring的value标签获取不值原样输出${}
来源:互联网 发布:ai人工智能设计软件 编辑:程序博客网 时间:2024/05/29 13:46
前提已经确保spring的配置文件以及读取到properties文件了我的配置是:
<!-- 引入属性文件 -->
<context:property-placeholder location="classpath:filer.properties" order="4" ignore-unresolvable="true"/>
spring的value标签注入properties配置文件的值在Controller中输入${"name"},但是在service层就可以
获取到配置文件的值。
经过上面的分析,足以说明是Controller层和service层的问题引起的,因为service层可以读取到值,
那么是什么原因导致Controller原样输出了${}这些东西呢?
@Value取不到值引出的spring的2种配置文件applicationContext.xml和xxx-servlet.xml
我的另一篇博客有一种解决办法,但是感觉不够好(需要的可以进入博客去找下),那种办法就是在每个xxx-servlet.xml中都扫描配置文件,
那我这里介绍的就是在applicationContext.xml中扫描一次,但是暴露自己的Id,在其他的xxx-servlet.xml中引入这个对象就可以了,下面是配置
applicationContext.xml扫描方式:
<!-- 引入属性文件 -->
<bean id="global" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<array>
<value>classpath:config/file.properties</value>
</array>
</property>
</bean>
这里暴露的Id是global,
下面是xxx-servlet.xml的配置文件:
<!-- 引入其他容器的配置 -->
<context:property-placeholder properties-ref="global" />
这样就可以注入对象了,下面有个注意点:(不要el表达式写多了这里后面写空格,除非你的配置文件名称的后面真的有空格,不如会找不到)
正确写法:@Value(value = "${file.serverPath}")
错误写法:@Value(value = "${file.serverPath }")
<!-- 引入属性文件 -->
<context:property-placeholder location="classpath:filer.properties" order="4" ignore-unresolvable="true"/>
spring的value标签注入properties配置文件的值在Controller中输入${"name"},但是在service层就可以
获取到配置文件的值。
经过上面的分析,足以说明是Controller层和service层的问题引起的,因为service层可以读取到值,
那么是什么原因导致Controller原样输出了${}这些东西呢?
@Value取不到值引出的spring的2种配置文件applicationContext.xml和xxx-servlet.xml
我的另一篇博客有一种解决办法,但是感觉不够好(需要的可以进入博客去找下),那种办法就是在每个xxx-servlet.xml中都扫描配置文件,
那我这里介绍的就是在applicationContext.xml中扫描一次,但是暴露自己的Id,在其他的xxx-servlet.xml中引入这个对象就可以了,下面是配置
applicationContext.xml扫描方式:
<!-- 引入属性文件 -->
<bean id="global" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<array>
<value>classpath:config/file.properties</value>
</array>
</property>
</bean>
这里暴露的Id是global,
下面是xxx-servlet.xml的配置文件:
<!-- 引入其他容器的配置 -->
<context:property-placeholder properties-ref="global" />
这样就可以注入对象了,下面有个注意点:(不要el表达式写多了这里后面写空格,除非你的配置文件名称的后面真的有空格,不如会找不到)
正确写法:@Value(value = "${file.serverPath}")
错误写法:@Value(value = "${file.serverPath }")
阅读全文
0 0
- spring的value标签获取不值原样输出${}
- <pre>标签让<textarea>标签的内容原样输出
- <pre>标签让<textarea>标签的内容原样输出
- 如何原样输出html标签
- html格式 保持原样输出的标签 需加pre标签
- 获取input标签的value
- struts2中,解决property标签原样输出HTML代码的问题
- 原样输出
- js获取li标签的value值
- spring的value获取不到值
- 文本原样输出问题
- 原样输出html
- txt文件原样存入数据库,原样输出
- a标签获取value值
- 难度0 茵茵的第一课(原样输出)
- idea 下Jsp el表达式原样输出的问题
- jquery获取struts2标签<s:select> 里的key value
- 获取select标签的文本内容以及Value值
- VS2013 加快编译速度 的方法整理
- 深度学习笔记 —— SVM 支持向量机
- 汇编模拟器一(单一语句简单寄存器)
- 时间戳获取
- 【Java面试题】之CAS原理深度分析
- spring的value标签获取不值原样输出${}
- 除了助长“假新闻”的嚣张气焰,AI还可以为真正的新闻出把力
- faster rcnn 训练自己的数据(python)
- 获取手机sd卡中的音乐并点击播放
- VIM 个人常用快捷键总结
- spark on yarn 的那些坑
- html5 video标签嵌入视频
- 深入理解Spring MVC 思想
- 网康上网行为管理NI3200-40