Push can not get UI instance using Spring

Hi all,

I am trying to send a message from a Spring Service to a Vaadin View using “ru.xpoft.vaadin” plugin.

All my views and UI are working using prototype scope, but when I try to send a message from a service “singleton scope” to my view it gets null for the current UI.

Is there any reason for it? UI.getCurrent() returns null.

I’d appreciate any help.

For example:

@Service
class service{
public void send(){
Broadcaster.broadcast(“miau”);
}
}

@Component
@Scope(SCOPE_PROTOTYPE)
@VaadinView(value = “myView”)
class MyView implements BroadcastListener{

@PostConstruct
public void init() {
    Broadcaster.register(this);
}
@Override
public void receiveBroadcast(final String message) {
    UI.getCurrent().access(new Runnable() {
        @Override
        public void run() {
            LOGGER.info(Thread.currentThread().getName() + ": " + message);
        }
    });
}

@Override
public void detach() {
    Broadcaster.unregister(this);
}

}

This usually happens when the component (view) is not attached with UI. I don’t see a reason to make UI class prototype scope. Spring might be returning new UI every time due to scope and View is not attached to new UI.

Can you change the UI scope to some other wider scope like @scopeUI