项目开发中,使用@value注解获取不到配置文件里面的属性字段。

检查配置文件,在spring的配置文件中有配置读取,如下:

<!-- 使用spring自带的占位符替换功能 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- 允许JVM参数覆盖 -->
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<!-- 忽略没有找到的资源文件 -->
<property name="ignoreResourceNotFound" value="true" />
<!-- 配置资源文件 -->
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:application.properties</value>
</list>
</property>
</bean>

这是没有问题的。启动的时候,也正常,但就是死活获取不到属性值。

经过漫长的尝试,和查找资料,综合分析:原来是spring,和springmvc父子容器的问题:

springmvc并不能获取到spring读取到的配置文件。

解决方法:在springmvc 配置文件中配置一下扫描,如下:

    <context:property-placeholder location="classpath:application.properties"/>

问题解决。

Spring 出现Could not resolve placeholder问题的解决方法的更多相关文章

  1. spring定时任务执行两次的原因与解决方法

    spring定时任务,本地执行一次,放到服务器上后,每次执行时会执行两次,原因及解决办法. http://blog.csdn.net/yaobengen/article/details/7031266 ...

  2. Spring中报"Could not resolve placeholder"的解决方案

    除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...

  3. Spring中报"Could not resolve placeholder"的解决方案(引入多个properties文件)

    除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...

  4. Spring MVC @RequestBody自动转JSON HTTP415错误解决方法

    转自:http://blog.csdn.net/tiantiandjava/article/details/46125141 项目中想用@RequestBody直接接收json串转成对象 网上查了使用 ...

  5. spring cloud config---Could not resolve placeholder 'xxx' in string value "${xxx}"

    初学SpringCloud 跟着视频写配置 前前后后检查了许久,配置代码没问题 最后发现是client项目的配置文件名有问题,不应该是application.yml 而是bootstrap.yml 那 ...

  6. 修改ubuntu DNS的步骤/wget url报错: unable to resolve host address的解决方法

    wget url 报错:unable to resolve host address ‘url’,显然是无法解析主机地址,这就能看出是DNS解析的问题.解决办法就是配置可用的dns 一般是修改成为谷歌 ...

  7. IntelliJ IDEA下Cannot resolve symbol XXX的解决方法

    Idea导入maven项目后,运行能通过,但是打开一些类后,会出现Cannot resolve symbol XXX的错误提示. 考虑几种可能: 1.JDK版本,设置JDK和Maven的JDK版本. ...

  8. IntelliJ IDEA下"Cannot resolve symbol 'log'"的解决方法

    转自:https://my.oschina.net/greatqing/blog/703989 最近接手了一个Maven项目,IDE使用的是IntelliJ IDEA,导入后可以编译运行.但是输出日志 ...

  9. CentOS yum 命令出现 [Errno 14] curl#6 - &quot;Couldn&#39;t resolve host ...&quot; 的解决方法

    安装svn的时候,发现报错说一个地址无法訪问. # yum list | grep subversion http://opensource.wandisco.com/centos/7/svn-1.8 ...

随机推荐

  1. html注册栏网页练习代码

    html body>     <form action="#" method="get">         <div>       ...

  2. servlet实现mysql数据库分页

    一.分页所需要的sql语句准备 select * from table limit m,n其中m是指记录开始的index,从0开始,表示第一条记录n是指从第m+1条开始,取n条. 例如:select ...

  3. 使用rke快速安装K8s集群

    操作系统 centos 7.5 yum update -y yum install docker -y 关闭防火墙.selinux 下载rke helm https://github.com/helm ...

  4. ToastUtils 工具类

    package com.example.grenaderose.redthunder.utils; import android.content.Context; import android.os. ...

  5. Centos 6.5使用vsftpd配置FTP服务器教程

    Centos 6.5使用vsftpd配置FTP服务器教程什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用.vsftpd 的名字代表”ver ...

  6. 记录-eureka

    我的工程目录是这样的: eureka- server:服务端 EurekaServerApplication的内容: 服务端配置文件内容: eureka-server :服务端 pom 文件: < ...

  7. [leetcode]68. Text Justification文字对齐

    Given an array of words and a width maxWidth, format the text such that each line has exactly maxWid ...

  8. windows下的mongodb安装与配置

    一.下载mongodb安装文件 https://www.mongodb.com/download-center/community 选择zip压缩包方式,如:mongodb-win32-x86_64- ...

  9. tiny4412 --Uboot移植(4) 串口

    开发环境:win10 64位 + VMware12 + Ubuntu14.04 32位 工具链:linaro提供的gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-g ...

  10. Visual Studio Installer 使用案例

    1.创建自定义操作 一步:新建“安装程序类”文件 2.重写函数: public override void Install(IDictionary stateSaver) { base.Install ...