web-dev-qa-db-fra.com

L'utilisation de JSF 2.2.9 sur Spring + Tomcat provoque Java.lang.NoClassDefFoundError: javax/enterprise/context/spi/Contextual

J'ai besoin d'utiliser des attributs HTML personnalisés dans les composants JSF, et pour cela, la seule solution que j'ai trouvée est d'utiliser JSF 2.2, de cette façon:

<f:passThroughAttribute name="data-toggle" value="modal" />

Le problème est que j'utilise Spring + Tomcat et que je ne peux rien y changer car je n'ai pas le temps. Chaque fois que je démarre mon serveur, j'ai l'erreur suivante:

Informações: CDI @ViewScoped manager unavailable
Java.lang.NoClassDefFoundError: javax/enterprise/context/spi/Contextual

Je sais que cela se produit parce que je n'utilise pas CDI, mais comme je l'ai dit, je ne peux pas passer de Spring à CDI à cause du temps. 

Comment puis-je résoudre ce problème ? Je dois utiliser JSF 2.2 (Parce que les attributs HTML personnalisés) et Spring.

RESOLU:

Ce problème résolu, je rétrograde à JSF 2.2.6 et l'erreur s'arrête.

Trace de la pile:

Fev 01, 2015 4:13:57 PM com.Sun.faces.application.view.ViewScopeManager <init>
Informações: CDI @ViewScoped manager unavailable
Java.lang.NoClassDefFoundError: javax/enterprise/context/spi/Contextual
at com.Sun.faces.application.view.ViewScopeManager.<init>(Unknown Source)
at com.Sun.faces.application.view.ViewScopeManager.getInstance(Unknown Source)
at com.Sun.faces.application.view.ViewScopeEventListener.processEvent(Unknown Source)
at javax.faces.event.SystemEvent.processListener(Unknown Source)
at javax.faces.event.ComponentSystemEvent.processListener(Unknown Source)
at com.Sun.faces.application.ApplicationImpl.processListeners(Unknown Source)
at com.Sun.faces.application.ApplicationImpl.invokeListenersFor(Unknown Source)
at com.Sun.faces.application.ApplicationImpl.publishEvent(Unknown Source)
at javax.faces.component.UIViewRoot.getViewMap(Unknown Source)
at javax.faces.component.UIViewRoot.getViewMap(Unknown Source)
at com.Sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.handle(Unknown Source)
at com.Sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(Unknown Source)
at com.Sun.faces.mgbean.BeanManager.createAndPush(Unknown Source)
at com.Sun.faces.mgbean.BeanManager.create(Unknown Source)
at com.Sun.faces.el.ManagedBeanELResolver.resolveBean(Unknown Source)
at com.Sun.faces.el.ManagedBeanELResolver.getValue(Unknown Source)
at com.Sun.faces.el.DemuxCompositeELResolver._getValue(Unknown Source)
at com.Sun.faces.el.DemuxCompositeELResolver.getValue(Unknown Source)
at org.Apache.el.parser.AstIdentifier.getValue(AstIdentifier.Java:71)
at org.Apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.Java:189)
at com.Sun.faces.facelets.el.TagValueExpression.getValue(Unknown Source)
at javax.faces.component.UIComponentBase$AttributesMap.get(Unknown Source)
at com.Sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.get(Unknown Source)
at javax.el.MapELResolver.getValue(MapELResolver.Java:52)
at com.Sun.faces.el.DemuxCompositeELResolver._getValue(Unknown Source)
at com.Sun.faces.el.DemuxCompositeELResolver.getValue(Unknown Source)
at org.Apache.el.parser.AstValue.getValue(AstValue.Java:169)
at org.Apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.Java:189)
at com.Sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(Unknown Source)
at com.Sun.faces.facelets.el.TagValueExpression.getValue(Unknown Source)
at com.Sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(Unknown Source)
at com.Sun.faces.application.ApplicationImpl.createComponent(Unknown Source)
at com.Sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(Unknown Source)
at com.Sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(Unknown Source)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(Unknown Source)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(Unknown Source)
at com.Sun.faces.facelets.tag.composite.ImplementationHandler.apply(Unknown Source)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(Unknown Source)
at com.Sun.faces.facelets.compiler.NamespaceHandler.apply(Unknown Source)
at com.Sun.faces.facelets.compiler.EncodingHandler.apply(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFacelet.include(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFacelet.include(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(Unknown Source)
at com.Sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyCompositeComponent(Unknown Source)
at com.Sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyNextHandler(Unknown Source)
at com.Sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(Unknown Source)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(Unknown Source)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(Unknown Source)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(Unknown Source)
at com.Sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(Unknown Source)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(Unknown Source)
at com.Sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(Unknown Source)
at com.Sun.faces.facelets.tag.ui.CompositionHandler.apply(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(Unknown Source)
at com.Sun.faces.facelets.tag.ui.InsertHandler.apply(Unknown Source)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(Unknown Source)
at com.Sun.faces.facelets.compiler.NamespaceHandler.apply(Unknown Source)
at com.Sun.faces.facelets.compiler.EncodingHandler.apply(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFacelet.include(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFacelet.include(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFacelet.include(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(Unknown Source)
at com.Sun.faces.facelets.tag.ui.CompositionHandler.apply(Unknown Source)
at com.Sun.faces.facelets.compiler.NamespaceHandler.apply(Unknown Source)
at com.Sun.faces.facelets.compiler.EncodingHandler.apply(Unknown Source)
at com.Sun.faces.facelets.impl.DefaultFacelet.apply(Unknown Source)
at com.Sun.faces.application.view.FaceletViewHandlingStrategy.buildView(Unknown Source)
at com.Sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
at com.Sun.faces.lifecycle.Phase.doPhase(Unknown Source)
at com.Sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
at javax.faces.webapp.FacesServlet.service(Unknown Source)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:304)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.Java:72)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at br.com.jwebbuild.filter.LoginFilter.doFilter(LoginFilter.Java:73)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.Java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:76)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:240)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:164)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:462)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:164)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:100)
at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:562)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:395)
at org.Apache.coyote.http11.Http11Processor.process(Http11Processor.Java:250)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:188)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:302)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
at Java.lang.Thread.run(Thread.Java:744)
Caused by: Java.lang.ClassNotFoundException: javax.enterprise.context.spi.Contextual
at org.Apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.Java:1676)
at org.Apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.Java:1521)
... 98 more
10
Shelly

J'ai le même problème et j'ai trouvé votre question sur Google (j'utilise JSF 2.2.9), avec la réponse de hwellmann, j'ai ajouté ces dépendances sur pom.xml de mon projet maven:

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

et le problème résolu, merci!

18
wryel

Avez-vous inclus le cdi-api.jar dans votre configuration? 

Cela ne signifie pas que vous devez utiliser CDI dans votre application, mais les classes de l'API doivent être présentes pour satisfaire les dépendances de JSF.

8
Harald Wellmann

Vous utilisez probablement le @ViewScoped de javax.faces.bean, il a été ajouté dans JSF 2.0. Essayez d’utiliser l’annotation de javax.faces.view, ajoutée à JSF 2.2.

0
Luiz