Spring CDI@ViewScope bean功能不可用

Spring CDI@ViewScope bean功能不可用,spring,jsf,spring-boot,jsf-2.2,Spring,Jsf,Spring Boot,Jsf 2.2,我将JSF 2.2.14与Spring Boot 1.4.4一起使用,并定义了一个自定义视图范围,如下所示: public class FacesViewScope implements Scope { public static final String NAME = "view"; @Override public Object get(String name, ObjectFactory<?> objectFactory) { Fac

我将JSF 2.2.14与Spring Boot 1.4.4一起使用,并定义了一个自定义视图范围,如下所示:

public class FacesViewScope implements Scope {

    public static final String NAME = "view";

    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext == null) {
            throw new IllegalStateException("FacesContext.getCurrentInstance() returned null");
        }

        Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();

        if (viewMap.containsKey(name)) {
            return viewMap.get(name);
        } else {
            Object object = objectFactory.getObject();
            viewMap.put(name, object);

            return object;
        }
    }

    @Override
    public Object remove(String name) {
        return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name);
    }

    @Override
    public String getConversationId() {
        return null;
    }

    @Override
    public void registerDestructionCallback(String name, Runnable callback) {
        // Not supported by JSF for view scope
    }

    @Override
    public Object resolveContextualObject(String key) {
        return null;
    }
}
@Component("testBean")
@Scope("view")
页面运行正常,但我收到警告:

c.s.f.application.view.ViewScopeManager  : CDI @ViewScoped bean functionality unavailable

我只有在第一次访问页面时才收到此警告,因此我担心此警告是否意味着我做了错事或可能在将来导致问题。

您只需在maven项目的pom.xml上添加以下依赖项:

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.2</version>
</dependency>

javax.enterprise
CDIAPI
1.2

为什么我们需要添加这个新的依赖项?出于某种原因将javax.faces从2.2.6升级到2.2.20,添加
cdi-api
修复了它,谢谢@Cleo
<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.2</version>
</dependency>