<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=hikage" rel="nofollow">Gildas Cuisinier</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6637?redirect=false" rel="nofollow">SPR-6637</a></strong> and commented</p>
<p dir="auto"><a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java-basic-concepts" rel="nofollow">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java-basic-concepts</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@Configuration
public class AppConfig {
    @Bean
    public void MyService myService() {
        return new MyServiceImpl();
    }
}"><pre class="notranslate"><code class="notranslate">@Configuration
public class AppConfig {
    @Bean
    public void MyService myService() {
        return new MyServiceImpl();
    }
}
</code></pre></div>
<p dir="auto">I think 'void' is not necessary.</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398101454" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11298" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11298/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11298">#11298</a> Incorrect method signature in the first code snippet in section 3.11.1 of the spring documentation (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/f7b0a2c0a218a1278ae1c71d340a99e60d69128e/hovercard" href="https://github.com/spring-projects/spring-framework/commit/f7b0a2c0a218a1278ae1c71d340a99e60d69128e"><tt>f7b0a2c</tt></a></p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=js888" rel="nofollow">jacek szafranski</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9658?redirect=false" rel="nofollow">SPR-9658</a></strong> and commented</p>
<p dir="auto">If a default is specified for <code class="notranslate">@Value-annotated</code> field or attribute, PropertyPlaceholderHelper.parseStringValue assigns the default property value just after the search for the property fails with the first location but before all property locations are examined. As a result, the the field ends up with the default value instead of the value defined in a properties file.</p>
<p dir="auto">How to reproduce:</p>
<p dir="auto">&lt;bean id="propertyConfigurer1"<br>
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br>
&lt;property name="locations"&gt;<br>
&lt;list&gt;<br>
&lt;value&gt;classpath:file1.properties&lt;/value&gt;<br>
...</p>
<p dir="auto">&lt;bean id="propertyConfigurer2"<br>
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br>
&lt;property name="locations"&gt;<br>
&lt;list&gt;<br>
&lt;value&gt;classpath:file2.properties&lt;/value&gt;<br>
...</p>
<p dir="auto">file1.properties: property "prop" undefined</p>
<p dir="auto">file2.properties:<br>
prop=value of prop</p>
<p dir="auto">public class PropHolder {</p>
<p dir="auto"><code class="notranslate">@Value</code>("${prop:defaultValue}")<br>
private String propValue;</p>
<p dir="auto">// ...</p>
<p dir="auto">}</p>
<p dir="auto">If propertyConfigurer1 is looked up first, the property "prop" is not found in "file1.properties" file, resulting in immediately assigning the default "defaultValue" to the propValue instance variable. Spring then looks up propertyConfigurer2. However, it's not going to read the prop value which is defined in its location(s), because it already has the default value and uses it as a key for further search.</p>
<p dir="auto">It looks like the following resolution order for <code class="notranslate">@Value</code> is more sane:</p>
<ol dir="auto">
<li>look up all locations in all property placeholders</li>
<li>use the default specified in the annotation only when look-up in all locations fails</li>
</ol>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.3</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398152701" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14356" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14356/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14356">#14356</a> Default values in property placeholder hierarchy applied too early (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">5 votes, 3 watchers</p>