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
- <Context-param>
- <Param-Name> contextconfiglocation </param-Name>
- <Param-value>
- WEB-INF/config/spring/Dao. xml,
- WEB-INF/config/spring/dfs. xml
- </Param-value>
- </Context-param>
If the two XML files are separated
XML Code
- <! -- Dao. xml -->
- <Context: Property-placeholder location = "WEB-INF/config/DB/dbconnect. properties"/>
- <! -- DFS. xml -->
- <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
- <Context: Property-placeholder location = ""/>
- <Context: Property-placeholder location = ""/>
Is not allowed.
Solution:
(1) In spring 3.0, you can write:
XML Code
- <Context: Property-placeholder location = "XXX. properties" ignore-unresolvable = "true"
- />
- <Context: Property-placeholder location = "yyy. properties" ignore-unresolvable = "true"
- />
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
- <Bean id = "casual" class = "org. springframework. Beans. Factory. config. propertyplaceholderconfigurer">
- <Property name = "location" value = "XXX. properties"/>
- <Property name = "ignoreunresolvableplaceholders" value = "true"/>
- </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.