Solution for "cocould not resolve Placeholder" reported in spring-multi-attribute file parameter settings

Source: Internet
Author: User

 

Except for the properites file path and spelling errors, "cocould not resolve Placeholder" may be caused by the use of multiple propertyplaceholderloaders or multiple <context: Property-placeholder>.

 

For example, I have a Dao. xml file that reads dbconnect. properties, and a DFS. xml file that reads dfsmanager. properties. Then the Web. xml file loads the two XML files in a unified manner.

XML Code
  1. <Context-param>
  2. <Param-Name> contextconfiglocation </param-Name>
  3. <Param-value>
  4. WEB-INF/config/spring/Dao. xml,
  5. WEB-INF/config/spring/dfs. xml
  6. </Param-value>
  7. </Context-param>

If the two XML files are separated

XML Code
  1. <! -- Dao. xml -->
  2. <Context: Property-placeholder location = "WEB-INF/config/DB/dbconnect. properties"/>
  3. <! -- DFS. xml -->
  4. <Context: Property-placeholder location = "WEB-INF/config/dfs/dfsmanager. properties"/>

Then, "cocould not resolve Placeholder" will be displayed ".

 

Remember to write data directly when one spring file or multiple spring files are uniformly loaded.

XML Code
  1. <Context: Property-placeholder location = ""/>
  2. <Context: Property-placeholder location = ""/>

Is not allowed.

 

Solution:

(1) In spring 3.0, you can write:

XML Code
  1. <Context: Property-placeholder location = "XXX. properties" ignore-unresolvable = "true"
  2. />
  3. <Context: Property-placeholder location = "yyy. properties" ignore-unresolvable = "true"
  4. />

Note that ignore-unresolvable = "true" must be added to both instances.

 

(2) In spring 2.5, <context: Property-placeholder> does not have the ignore-unresolvable attribute. In this case, you can use propertyplaceholderconfigurer instead. In fact, <context: Property-placeholder location = "XXX. properties" ignore-unresolvable = "true"/> is equivalent to the following Configuration:

Java code
  1. <Bean id = "casual" class = "org. springframework. Beans. Factory. config. propertyplaceholderconfigurer">
  2. <Property name = "location" value = "XXX. properties"/>
  3. <Property name = "ignoreunresolvableplaceholders" value = "true"/>
  4. </Bean>

Because of this, writing multiple propertyplaceholderregistrers without adding the ignoreunresolvableplaceholders attribute also produces "cocould not resolve Placeholder ".

 

Although the two are equivalent, it is estimated that you still like to write more <context: Property-placeholder>, Which is simpler after all. Therefore, if it is spring 3.0, it is no longer easy to use the solution (1). If it is spring 2.5, it takes some effort to rewrite it to propertyplaceholderconfigurer.

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.