vaadin springboot and null pointer when using autowire for EventBus.UIEvent

Hi,

I am using vaadin springboot and I getting null pointer when using autowire for EventBus.UIEventBus.

What I am trying to do in below code is pass the event from loginview to my main vaadin UI class. And a null pointer I am getting is in LoginView class.

Any input are appreciated . Thank you.

import com.vaadin.annotations.Theme;
import com.vaadin.server.Responsive;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinSession;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.UI;
import com.vaadin.ui.themes.ValoTheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;
import org.vaadin.spring.events.EventBusListener;
import telosws.domain.User;
import telosws.view.MainView;

import java.util.Locale;

/**

  • Created by karthikmarupeddi on 5/28/15.
    */
    @SpringUI
    @Theme(“valo”)
    public class MyVaadinUI extends UI implements EventBusListener {

@Autowired
EventBus.UIEventBus eventBus;

@Override
protected void init(VaadinRequest vaadinRequest) {

setLocale(Locale.US);

Responsive.makeResponsive(this);
addStyleName(ValoTheme.UI_WITH_MENU);

updateContent();

}

/**

  • Updates the correct content for this UI based on the current user status.
  • If the user is logged in with appropriate privileges, main view is shown.
  • Otherwise login view is shown.
    */
    private void updateContent() {
    User user = (User) VaadinSession.getCurrent().getAttribute(
    User.class.getName());
    if (user != null && “admin”.equals(user.getRole())) {
    // Authenticated user
    setContent(new MainView());
    removeStyleName(“loginview”);
    getNavigator().navigateTo(getNavigator().getState());
    } else {
    //setContent(new LoginView());
    setContent(new MainView());
    addStyleName(“loginview”);
    }
    }

/**

  • Called when an event has been received.
  • @param event the event, never {@code null}.
    */
    @Override
    public void onEvent(org.vaadin.spring.events.Event event) {

System.out.println(“printing data”+event.toString());
setContent(new MainView());
removeStyleName(“loginview”);
getNavigator().navigateTo(getNavigator().getState());

}
}

//login view class

package telosws.view;

import com.vaadin.event.ShortcutAction;
import com.vaadin.server.FontAwesome;
import com.vaadin.server.Responsive;
import com.vaadin.spring.annotation.UIScope;
import com.vaadin.ui.*;
import com.vaadin.ui.themes.ValoTheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.spring.events.EventBus;

/**

  • Created by karthikmarupeddi on 5/30/15.
    */
    @UIScope
    public class LoginView extends VerticalLayout {

@Autowired
EventBus.UIEventBus eventBus;

public LoginView() {
eventBus.subscribe(this);
setSizeFull();

Component loginForm = buildLoginForm();
addComponent(loginForm);
setComponentAlignment(loginForm, Alignment.MIDDLE_CENTER);
}

private Component buildLoginForm() {
final VerticalLayout loginPanel = new VerticalLayout();
loginPanel.setSizeUndefined();
loginPanel.setSpacing(true);
Responsive.makeResponsive(loginPanel);
loginPanel.addStyleName(“login-panel”);

loginPanel.addComponent(buildLabels());
loginPanel.addComponent(buildFields());
loginPanel.addComponent(new CheckBox(“Remember me”, true));
return loginPanel;
}

private Component buildLabels() {
CssLayout labels = new CssLayout();
labels.addStyleName(“labels”);

Label welcome = new Label(“Welcome”);
welcome.setSizeUndefined();
welcome.addStyleName(ValoTheme.LABEL_H4);
welcome.addStyleName(ValoTheme.LABEL_COLORED);
labels.addComponent(welcome);

Label title = new Label(“Connect2X”);
title.setSizeUndefined();
title.addStyleName(ValoTheme.LABEL_H3);
title.addStyleName(ValoTheme.LABEL_LIGHT);
labels.addComponent(title);
return labels;
}

private Component buildFields() {
HorizontalLayout fields = new HorizontalLayout();
fields.setSpacing(true);
fields.addStyleName(“fields”);

final TextField username = new TextField(“Username”);
username.setIcon(FontAwesome.USER);
username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

final PasswordField password = new PasswordField(“Password”);
password.setIcon(FontAwesome.LOCK);
password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

final Button signin = new Button(“Sign In”);
signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
signin.setClickShortcut(ShortcutAction.KeyCode.ENTER);
signin.focus();

fields.addComponents(username, password, signin);
fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

signin.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(final Button.ClickEvent event) {
eventBus.publish(LoginView.this, “Hello World from UI”);

}
});

return fields;

}

}