这是因为 Spring和SpringMVC存在父子容器关系
Spring容器 :父容器
SpringMVC容器 : 子容器
和Java中继承类似,容器访问原理也是这样,由于我们只在spring父容器applicationContext.xml中配置了<context:property-placeholder location=“classpath:config/config.properties” ignore-unresolvable=“true” />,@Value的时候不会主动去父容器寻找配置信息。
解决办法
此时可以在SpringMVC-servlet.xml子容器的xml文件中也加入
<bean id="prop" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">