Recently, I encountered a very strange problem. Spring controller can inject objects, but it cannot inject placehoder with @ value, while other @ values are normal.
It was suddenly found that this was a strange problem. In web. XML, both spring-MVC Servlet and spring context listener were configured. This causes two sets of files to be initialized. For some reason, the placeholder cannot be shared during the two initialization processes, so the spring context listener is removed and
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath *: spring/*. xml </param-value>
Move to the spring-MVC servlet configuration and let spring-MVC initialize, so that the Spring-MVC file can be managed together with other spring configuration files, and the placeholder only needs one copy, everyone is happy:
Original:
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath *: spring/*. xml </param-value>
</Context-param>
<Listener>
<Listener-class> org. springframework. Web. Context. contextloaderlistener </listener-class>
</Listener>
<Servlet>
<Servlet-Name> springmvc </servlet-Name>
<Servlet-class> org. springframework. Web. servlet. dispatcherservlet </servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
Current:
<Servlet>
<Servlet-Name> springmvc </servlet-Name>
<Servlet-class> org. springframework. Web. servlet. dispatcherservlet </servlet-class>
<Init-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath *: spring/*. xml </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>