Use Value annotation to appear Could not resolve placeholder'email_username' in value "${email_username}" step on the pit! ! ! ! !

1. Problems encountered

When working on the project, some configuration was added to the properties configuration file, but when it was introduced, the error Could not resolve placeholder'XXX' in value "${XXX}" always appeared. I checked that the annotations on the class also exist, but it is injected Don't go in.

2. Reason

Because of the discovery mechanism of reflection scanning adopted by spring, that is, there can only be one <context:property-placeholder /> tag in the spring container. If there are more than one tag, then whoever comes last will replace the original one. The others will be ignored, and whoever loads it later will be used.

3. Solution

1. Integrate into one and load it together
<context:property-placeholder location="classpath:*.properties" />
Note: There can only be one, if there is this label behind, it will be replaced
. 2. In each label After adding ignore-unresolvable="true", even if multiple tags are loaded, they will be retained and will not be overwritten.

Reference:
https://www.cnblogs.com/yes-V-can/p/6389571.html
https://blog.csdn.net/yu870646595/article/details/50979338
https://blog.csdn.net/ u010668907/article/details/79410665

Da Hang! ! ! ! ! !

Guess you like

Origin blog.csdn.net/weixin_43431123/article/details/112000011