title: How to get current bean name/id to use it inside bean initialization for building placeholder name
body: <p>Hi Spring Framework experts!</p>
  <p>I need to make 10+ of similar beans configurable with using placeholders. The only difference between them is unique placeholder keys (<code>${bean1.key}</code>, <code>${bean2.key}</code> and so on). If I do it straight, I should copy bean definition 10+ times and change only first part of placeholder. So I'm thinking how to avoid this duplication.</p>
  <p>I would like to generate placeholder string dynamically. As dynamic part I would like to use current bean <code>ID</code> (or alternatively it's field value).
  It should be something like this.</p>
  <pre><code>&lt;!-- Template --&gt;
  &lt;bean id=&quot;mainProfile&quot; abstract=&quot;true&quot; class=&quot;com.company.SomeClass&quot;&gt;
      &lt;property name=&quot;role&quot; value=&quot;${${this.beanName}.role:NA}&quot;&gt;
      &lt;!-- other properties initialized in same way --&gt;
  &lt;/bean&gt;
  &lt;!-- Instances --&gt;
  &lt;bean id=&quot;profile1&quot; parent=&quot;mainProfile&quot;/&gt;
  &lt;bean id=&quot;profile2&quot; parent=&quot;mainProfile&quot;/&gt;
  &lt;bean id=&quot;profile3&quot; parent=&quot;mainProfile&quot;/&gt;
  </code></pre>
  <p>As result, property <code>role</code> for all beans can be initialized by adding next lines to the <code>app.properties</code>:</p>
  <pre><code>profile1.role=admin
  profile2.role=guest
  profile3.role=editor
  </code></pre>
  <p>I've tried next approaches:</p>
  <ol>
  <li><a href="http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/beans/factory/BeanNameAware.html" rel="nofollow noreferrer" title="BeanNameAware">BeanNameAware</a> + SpEL</li>
  </ol>
  <p>Unfortunately, <code>bean name</code> is <code>null</code> before bean initialization. I believe this approach may work only if bean name can be provided by Spring out of the box and it has predefined placeholder. Am I right? Does Spring have such system variables?</p>
  <ol start="2">
  <li><code>Factory</code> for constructing placeholder names dynamically.</li>
  </ol>
  <p>As for me it can be used for generating values, but not placeholders names.</p>
  <p>I would appreciate for any advices!</p>