title: Spring reference a property from a property bean
body: <p>I have created a spring configuration file that works well.</p>
  
  <p>My next step was to separate user configuration properties from system properties.</p>
  
  <p>I have decided to create additional xml file with beans that will be configured by the user.</p>
  
  <p>I had problem to create few such logical beans encapsulating properties that will be used by real class beans:</p>
  
  <p>I have found over the net an option to reference proprieties in such way:</p>
  
  <p>UserConf.xml</p>
  
  <pre><code>&lt;bean id="numberGuess" class="x..."&gt;
      &lt;property name="randomNumber" value="5"/&gt;
  
      &lt;!-- other properties --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>SystemConf.xml</p>
  
  <pre><code>&lt;import resource="UserConf.xml" /&gt;
  
  &lt;bean id="shapeGuess" class="y..."&gt;
      &lt;property name="initialShapeSeed" value="#{ numberGuess.randomNumber }"/&gt;
  
      &lt;!-- other properties --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But my problem is that i need <code>x...</code> class to be something logical that shouldn't be initialized at all, and i don't want it to disclose any info of the class hierarchy of the system since it should be only in use configuration xml file.</p>
  
  <p><strong>Solution1</strong> is to create a Java object representing this proprieties:</p>
  
  <pre><code>public class MyProps(...)
  </code></pre>
  
  <p>and add a bean parent in the spring system configuration:</p>
  
  <pre><code>&lt;bean id="MyProps" class="path to MyProps"/&gt;
  </code></pre>
  
  <p>in the user side change the previous bean to be:</p>
  
  <pre><code>&lt;bean id="numberGuess" parent="MyProps"&gt;
      &lt;property name="randomNumber" value="5"/&gt;
  
      &lt;!-- other properties --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Solution2</strong> is to use flat configuration file just like Database.props, and load it using factory.</p>
  
  <p><strong>Solution3</strong> is to use Spring Property Placeholder configuration to load properties from XML properties file (e.g. <a href="http://rvsoni.wordpress.com/2012/03/15/spring-property-placeholder-configuration-to-load-properties-from-xml-properties-file/" rel="nofollow">example</a>), but here i simply don't know how to get a more complex nested structure of properties (properties need to be separated by different logical names, e.g. minNumber will be defined both under xAlgo and y algo).</p>
  
  <p>I don't like to create new Java class only to deal with this problem or to move my user configuration to a flat props file (i need the xml structure), is their any other solution??</p>