Could not resolve placeholder '' in value "${}"

背景

用Jenkins构建maven自动化打包时,因为需要从properties文件读取参数来区分是本地Debug版还是正式上线版,配置完就不能用了。

Failed to load ApplicationContext

原因

两个错误都出现,因为本来是用IDEA的默认配置的resources文件,由于需要参数化构建,所以修改了pom.xml

<build> 
  <resources>
      <resource>
        <filtering>true</filtering>
        <directory>${project.basedir}/src/main/resources</directory>
        <includes>
          <include>*.properties</include>
        </includes>
      </resource>
    </resources>
  </build>

《Could not resolve placeholder '' in value

实际上工程的资源文件如上图,如果写为*.properties,那么在target目录下就会发现,所有的xml配置文件也都消失了,只剩下一个log4j.properties。

解决方法

<include>*.properties</include>改为

 <include>**/*</include>
Could not resolve placeholder ” in value “${}”

原因

在spring mvc中使用注解方式获取properties中的值@Value(“${propertieName}”) ,在spring的application.xml里配置过后,还需要在spring mvc的配置文件里配置一遍,否则spring mvc不认识。

解决方法

在spring-mvc.xml里添加该句

<context:property-placeholder location="classpath:properties/*.properties"/>
点赞