Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I inject a property value into a Spring Bean which was configured using annotations?
    primarykey
    data
    text
    <p>I have a bunch of Spring beans which are picked up from the classpath via annotations, e.g.</p> <pre><code>@Repository("personDao") public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao { // Implementation omitted } </code></pre> <p>In the Spring XML file, there's a <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html" rel="noreferrer">PropertyPlaceholderConfigurer</a> defined:</p> <pre class="lang-xml prettyprint-override"><code>&lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location" value="/WEB-INF/app.properties" /&gt; &lt;/bean&gt; </code></pre> <p>I want to inject one of the properties from app.properites into the bean shown above. I can't simply do something like </p> <pre class="lang-xml prettyprint-override"><code>&lt;bean class="com.example.PersonDaoImpl"&gt; &lt;property name="maxResults" value="${results.max}"/&gt; &lt;/bean&gt; </code></pre> <p>Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations). I've got as far as the following:</p> <pre><code>@Repository("personDao") public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao { @Resource(name = "propertyConfigurer") protected void setProperties(PropertyPlaceholderConfigurer ppc) { // Now how do I access results.max? } } </code></pre> <p>But it's not clear to me how I access the property I'm interested in from <code>ppc</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload