我正在 MyFaces 2.3.6 上使用 Primefaces 8.0 构建 JSF 2.3 应用程序,在 Tomcat 9 上运行。还使用 OpenWebBeans 2.0.18。
当我将范围从更改为时,我的一个 bean(控制器)给了我一个@RequestScoped
错误@ViewScoped
:
28-Sep-2020 13:12:07.368 SEVERE [main] org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces An error occured while initializing MyFaces: It's not allowed to call getReference(Bean, Type, CreationalContext) before AfterDeploymentValidation
java.lang.IllegalStateException: It's not allowed to call getReference(Bean, Type, CreationalContext) before AfterDeploymentValidation
at org.apache.webbeans.container.InjectableBeanManager.checkAfterDeploymentValidationFired(InjectableBeanManager.java:434)
at org.apache.webbeans.container.InjectableBeanManager.getReference(InjectableBeanManager.java:178)
at org.apache.myfaces.cdi.util.CDIUtils.resolveInstance(CDIUtils.java:65)
at org.apache.myfaces.cdi.util.CDIUtils.lookup(CDIUtils.java:52)
at org.apache.myfaces.flow.cdi.DefaultCDIFacesFlowProvider.getAnnotatedFlows(DefaultCDIFacesFlowProvider.java:52)
at org.apache.myfaces.flow.impl.AnnotatedFlowConfigurator.configureAnnotatedFlows(AnnotatedFlowConfigurator.java:42)
at org.apache.myfaces.config.FacesConfigurator.configureFlowHandler(FacesConfigurator.java:1713)
at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:619)
at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:456)
at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:70)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:190)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
bean 代码如下:
@Named
@ViewScoped
@ManagedBean
public class DashBoardController implements Serializable
{
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(DashBoardController.class.getName());
List<IdentityStatistics> idStats;
List<AuditStatistics> auditStats;
@Inject
private StatisticsService service;
@PostConstruct
public void init()
{
logger.log(Level.FINE, "Reading statistics from API");
FacesContext context = FacesContext.getCurrentInstance();
AuthToken token = (AuthToken)context.getExternalContext().getSessionMap().get(AuthService.SESSION_TOKEN);
...
}
...
}
切换回@RequestScoped
立即解决错误(但这不是我想要的)。错误中提到的getReference()
方法肯定不在我的代码中,所以它必须在某个框架库中。
我有另一个@ViewScoped
非常相似的 bean,它没有给我这个错误。显然,我错过了某个地方的差异,但对于我的生活,我无法发现它。
使用时可能导致此错误的原因是什么@ViewScoped
?