关于注入Notifications类的问题


#1

我在WEB模块下新建了一个自己类并给SPRING托管,我想注入GUI包中的Notifications,但是Spring无法找到这个类,求助
1、建立类如下:
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.Notifications;
import org.springframework.stereotype.Component;

import javax.inject.Inject;

@Component(NotificationUtil.NAME)
public class NotificationUtil {
public static final String NAME = “lims_NotificationUtil”;

@Inject
private Notifications notifications;

@Inject
private Messages messages;
}
2、启动的时候报错如下:
Error creating bean with name ‘lims_NotificationUtil’: Unsatisfied dependency expressed through field ‘notifications’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.haulmont.cuba.gui.Notifications’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject()}
3、类里注入的Message是没问题的,注入Notifications就报错了

请问这该怎么解决?


#2

Notifications 接口是 Screen API,每个标签页都有其单独的 Notifications 实例,因此不能在Service或者Component中直接注入。需要调用可以用下面这个方法,通过 AppUI.getCurrent() 获取当前 tab 的引用,然后在取其 Notifications。

Screen 中使用:

效果:


#3

非常感谢!:grin::grin::grin: