title: Vaadin Component as Spring bean
body: <p><strong>Question:</strong></p>
  
  <p>When Vaadin component could be a bean in spring container (<code>@SpringComponent</code> annotation)?</p>
  
  <p><strong>Question clarification:</strong></p>
  
  <p>I ask this question because I know that Vaadin View could be spring bean after using <code>@SpringView</code>.
  But if I annotate <code>Button</code> component with <code>@SpringComponent</code> it will be created only once. Can it make any problem?</p>
  
  <p><strong>Example:</strong></p>
  
  <p>I have a lot of JpaRepository bean:</p>
  
  <pre><code>public interface CustomerRepository extends JpaRepository&lt;Customer, Long&gt; 
  // ...
  
  public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
  // ...
  </code></pre>
  
  <p>And I want use them in different places - for example in a Tab component (in Vaadin TabSheet). So I have an idea - the <code>tabContent</code> can be also spring component:</p>
  
  <pre><code>@SpringView(name = "viewName")
  public class SomeView extends VerticalLayout implements View {
  
      @Autowired
      private SomeTabContent tabContent;
      //...
      public void init() { // call every view enter()
          removeAllComponents();
          // Initialize whole view.
          tabSheet.addTab(tabContent, /* ... */);
          // ...
      }
  </code></pre>
  
  <p>And then I can inject all needed beans:</p>
  
  <pre><code>@SpringComponent
  public class SomeTabContent extends VerticalLayout {
      @Autowired
      private CustomerRepository customerRepository;
  
      @Autowired
      private UserRepository UserRepository;
  }
  </code></pre>
  
  <p>Is it correct architecture? </p>
  
  <p>Note: I know that Vaadin has CDI and Data Binding features, but I don't want use them. I also know that I could manually create Spring application context in any place - but I think this is not proper way.</p>