【发布时间】:2017-01-28 08:34:48
【问题描述】:
我将 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;
}
}
并在Spring Boot主类中注册如下:
@Bean
public static CustomScopeConfigurer customScopeConfigurer() {
CustomScopeConfigurer configurer = new CustomScopeConfigurer();
configurer.setScopes(Collections.<String, Object>singletonMap(
FacesViewScope.NAME, new FacesViewScope()));
return configurer;
}
使用 spring 管理我的视图范围 bean 时如下:
@Component("testBean")
@Scope("view")
页面运行良好,但我收到警告:
c.s.f.application.view.ViewScopeManager : CDI @ViewScoped bean functionality unavailable
我仅在第一次访问该页面时收到此警告,因此我担心此警告是否意味着我做错了事或将来可能会导致问题。
【问题讨论】:
标签: spring jsf spring-boot jsf-2.2