title: Spring Autowired in new java object
body: <p>I am starting to work with Spring Boot and got a question about how to autowire Spring Beans in java Objects that are not managed by Springs application context.</p>
  
  <p>Scenario: In my Spring Boot application I want to code a scheduled task, that first fetches a list of master data of type "environment" from the database. For each "environment" object multiple asynchronous Rest calls will be executed which return some JSON Data (here "applicationServerData"). This data should be kept locally until all rest call responses arrived. After some processing the result will be written to the database.</p>
  
  <p>So I thought of creating some kind of processor class that is capable of holding the requested data locally. For each environment a new object will be created with the new operator:</p>
  
  <pre><code>@Slf4j
  public class EnvironmentProcessingServiceImpl implements
      EnvironmentProcessingService {
  
  @Autowired
  private DataManagementFacade dataManagementFacade;
  
  @Autowired
  @Qualifier(value = "mock")
  private ProductionDataClient productionDataClient;
  
  private Environment environment;
  
  private List&lt;ApplicationServerDataHolder&gt; applicationServerDataHolderList;
  
  public EnvironmentProcessingServiceImpl(Environment environment) {
      this.environment = environment;
      this.applicationServerDataHolderList = new ArrayList&lt;&gt;();
  }
  </code></pre>
  
  <p>The problem now is, that <code>@Autowired</code> wont work, because the objects are not managed by Spring, but i can not simply make it a <code>@service</code> because I need multiple instances if I want to hold data in the same class. I read about a solution with the <code>@Configurable</code> annotation. Is this good practice?</p>
  
  <p>Or should I make the class a <code>@service</code> and make another component that caches all the data and is wiped after the task finished to have empty lists for the next run?</p>
  
  <p>What do you think is good practice in this case.</p>