title: Autowiring class with dynamic param value in Spring
body: <p>I want to do the following in my Spring MVC application:</p>
  
  <ol>
  <li>Get some data from the database (It will return <code>List&lt;String&gt; list</code> ) in my @Service <code>MainService</code>.</li>
  <li>Use this <code>list</code> as a constructor parameter for other @Service <code>ConfigFactory</code> that I have currently @Autowired in <code>MainService</code>.</li>
  <li>Fire a method from <code>ConfigFactory</code> to get final result that will be added to ModelAndView in my @Controller class.</li>
  </ol>
  
  <p>I know it would be possible to this that way:</p>
  
  <p>ConfigFactory class:</p>
  
  <pre><code>@Service
  public class ConfigFactory(){
      public void init(List&lt;String&gt; list){
          //Use list to initialize ConfigFactory
      }
  
      public Result getResult(){
          //Do some business logic
          return result;
      }
  }
  </code></pre>
  
  <p>MainService class:</p>
  
  <pre><code>@Service
  public class MainService {
      @Autowired ConfigFactory configFactory;
  
      public Result method(){
          //Get list from database;
          configFactory.init(list);
          Result result = configFactory.getResult();
  
          //Create a Result that will be later added to controller ModelAndView. 
      }
  }
  </code></pre>
  
  <p>But it doesn't feel nice. So I'm stuck here. Does anyone have an idea how to properly realize this?</p>