Problems caused by spring MVC where placeholder is configured but placeholder cannot be injected (using annotation)

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.