I wrote a menubar as a custom layout in vaadin. It has a logout button which is autowired to custom a Session variable. The autowired variable can only be used after construction, so I added an init method annotated with PostConstruct:
public class Menu extends HorizontalLayout{
private Button logout = new Button("Logout");
@Autowired
private Session session;
@PostConstruct
private void init(){
logout.addClickListener((event) -> {
session.unsetUser();
Notification.show("Good bye");
getUI().getNavigator().navigateTo(LoginView.NAME);
});
addComponent(logout);
}
}
Since it is not a SpringBean, the PostConstruct will never run. How do I overcome this?