title: Design suggession on Spring component and multiple repositories
body: <p>I have an API component class and each of its business methods need different repositories. This is what I have for example:</p>
  
  <pre><code>@Component
  @Transactional (propagation = Propagation.SUPPORTS,
                  rollbackForClassName="java.lang.Throwable")
  @EnableTransactionManagement 
  public class TransactionApi
  {
      @Autowired
      private TransactionRepository repo;
      @Autowired
      private ProductRepository prodRepo;
      @Autowired
      private CustomerRepository custRepo;
      @Autowired
      private OrderRepository orderRepo;
      @Autowired
      private ContactRepository contactRepo;
      @Autowired
      private ShippingPrefsRepository shipPrefsRepo;
  
      @Transactional (readOnly=true)
      public Transaction getTransactionDetails(String transactionId)
      {
          return repo.findOne(transactionId);
      }
  
      @Transactional (readOnly=true)
      public Product getProductDetails(String productId)
      {
          return prodRepo.findOne(productId);
      }
  
      @Transactional (readOnly=true)
      public Customer getCustomerDetails(String customerId)
      {
          return custRepo.findOne(customerId);
      }
  
      public Order createOrder(Order order)
      {
          Order saved = orderRepo.save(order);
          return saved;
      }
  
      public Contact createContact(Contact contact)
      {
          Contact saved = contactRepo.save(contact);
          return saved;
      }
  
      public ShippingPreference createContact(ShippingPreference shipPref)
      {
          ShippingPreference saved = shipPrefsRepo.save(shipPref);
          return saved;
      }
  </code></pre>
  
  <p>Looking at above design, i have a lot of repositories used in one class and so not all are used each time this class is used. So i think initializing all of them upfront would be an overkill (I assume). I am worried that this might slow down my application or use lot of resources (memory). I will probably will have another 20 repositories when I am done with this class. </p>
  
  <p>My question is am I designing it correctly as it should be done? Or is there better way of doing it. Loading too many repositories into memory when each time just one of those are being used, isn't it inefficient way of doing it? Any suggestions/advice are appreciated.</p>