Question:
When Vaadin component could be a bean in spring container (@SpringComponent
annotation)?
Question clarification:
I ask this question because I know that Vaadin View could be spring bean after using @SpringView
.
But if I annotate Button
component with @SpringComponent
it will be created only once. Can it make any problem?
Example:
I have a lot of JpaRepository bean:
public interface CustomerRepository extends JpaRepository<Customer, Long>
// ...
public interface UserRepository extends JpaRepository<User, Long> {
// ...
And I want use them in different places - for example in a Tab component (in Vaadin TabSheet). So I have an idea - the tabContent
can be also spring component:
@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, /* ... */);
// ...
}
And then I can inject all needed beans:
@SpringComponent
public class SomeTabContent extends VerticalLayout {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private UserRepository UserRepository;
}
Is it correct architecture?
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.