title: Passing the bean ID from property file in Spring
body: <p>I have a springboot app that uses spring integration to route tcp messages between several components, it is working fine from a functional POV. I'm stuck on trying to clean up the code and replacing multiple hardcoded values (channel names) with constants declared in a property file :</p>
  
  <p>Actual example consists of several channels and a router : </p>
  
  <pre><code>&lt;int:channel id="input"&gt;
  
  &lt;int:channel id="outputA"/&gt;
  &lt;int:channel id="outputB"/&gt;
  &lt;int:channel id="outputC"/&gt;
  
  &lt;int:router method="determineTargetChannel" input-channel="input"&gt;
      &lt;beans:bean class="MyRouter"/&gt;
  &lt;/int:router&gt;
  </code></pre>
  
  <p>And MyRouter class : </p>
  
  <pre><code>@Component
  public class MyRouter {
  
      @Router
      public String determineTargetChannel(Object payload) {
          if (condition1) {
              return "outputA";
          } else if (condition2) {
              return "outputB";
          } else return "outputC";
      }    
  }
  </code></pre>
  
  <p>I didn't wanted to have the channels ids hardcoded in two places, both in the XML file and in the Router class as well (or any other class that could hold them as constants). </p>
  
  <p><strong>So I tried the following :</strong> </p>
  
  <p>1) Store the ids in a properties YML file : </p>
  
  <pre><code>router:
      channel:
          outputA: outputA
          outputB: outputB
          outputC: outputC
  </code></pre>
  
  <p>2) Update XML file : </p>
  
  <pre><code>&lt;int:channel id="input"&gt;
  
  &lt;int:channel id="${router.channel.outputA}"/&gt;
  &lt;int:channel id="${router.channel.outputB}"/&gt;
  &lt;int:channel id="${router.channel.outputC}"/&gt;
  
  &lt;int:router method="determineTargetChannel" input-channel="input"&gt;
      &lt;beans:bean class="MyRouter"/&gt;
  &lt;/int:router&gt;
  </code></pre>
  
  <p>3) Update MyRouter class : </p>
  
  <pre><code>@Component
  public class DARouter {
  
      @Value("${router.channel.outputA}")
      private String outputA;
  
      @Value("${router.channel.outputB}")
      private String outputB;
  
      @Value("${router.channel.outputC}")
      private String outputC;
  
      @Router
      public String determineTargetChannel(Object payload) {
          if (condition1) {
              return outputA;
          } else if (condition2) {
              return outputB;
          } else return outputC;
      }
  }
  </code></pre>
  
  <p><strong>The issue is</strong> that at the moment when Spring creates the beans declared in the XML file it doesn't resolve the properties values so it creates a bean with ID=${router.channel.outputA} instead of the actual value outputA.</p>
  
  <p>It is not an issue of not loading the properties file, because if I try to pass the properties to other fields (not bean ID) it works fine and the value is injected correctly, example : </p>
  
  <pre><code>&lt;int:router method="determineTargetChannel" input-channel="${router.channel.outputA}"&gt;
      &lt;beans:bean class="MyRouter"/&gt;
  &lt;/int:router&gt;
  </code></pre>