在controller中无法通过注解@Value获取到配置文件中定义的值

1. 默认的我们通常只在dao层用到jdbc的配置,然后使用到@Value注解获取到值。

 这时候会在spring-dao扫描中加入下面配置

    <context:property-placeholder location="classpath:jdbc.properties"  ignore-unresolvable="true"/>
    <context:property-placeholder location="classpath:config.properties"  ignore-unresolvable="true" />

2. 如果想在controller中使用@Value指定变量,则还需要在springmvc中加入同样的配置。

  <context:property-placeholder location="classpath:config.properties"  ignore-unresolvable="true" />
原文地址:https://www.cnblogs.com/30go/p/9808002.html