Vaadin Spring UI init hell

I’m using Vaadin 7.6.4 and the spring-vaadin-portlet/0.0.5 for VaadinSpringPortlet and @VaadinPortletUI annotations from ru.xpoft.vaadin.

I keep running into situations where init(VaadinRequest request) and @PostConstruct init() essentially conflict with eachother. This is the latest one:-

public class AbstractUI {
public void init(VaadinRequest request){

public class UI extends AbstractUI {
public void init(VaadinRequest request){
super.init(request);// ensure all my boiler-plate security stuff is init’d

public void init(){

public class MyComponentBean {

SomeService someService; // We need this to be instantiated so wait till post-construct to use it.

public void init(){

// userSetting needs to be set if not set per-session, provide some UI to do that if not found!
UserSetting userSetting = UI.getCurrent().getSession().getAttribute(“someUserSetting”);

if (user == null){
// load user login UI
User user = UI.getCurrent().getSession().getAttribute(“authenticatedUser”); /
/NPE here as UI.getCurrent() == null

userSetting = someService.getUserSetttingBasedOnUser(user);
[/code]Now I hear you saying already “just reverse it” and have the UI components attached in the init(VaadinRequest) method, but that gives me NPEs when attempting to access my @Autowired properties. I think that is likely the crux of my issue, and I need to investiage that more (some caught exceptions preventing init of lower-order components perhaps).

How is everyone else doing this? I’m avoiding just slamming in spring-boot / custom vaddin portlet / @Configuration based context for now.


You need to ensure the
has been instanciated before calling
at any point in your code. One way of doing that is by overriding the


method in your
class (which in your snippet is not extending a Vaadin component but I’m sure it is in your real code).

As an alternative, you could try to
lazyly initialize


Also, in case you are using defaults, making the beans prototype-scoped may be a good idea, but of course it depends on your requirements.