【问题标题】:com.sun.faces.spi.InjectionProvider not found by javax.faces-api when deploying JSF WAB to Jetty将 JSF WAB 部署到 Jetty 时 javax.faces-api 找不到 com.sun.faces.spi.InjectionProvider
【发布时间】:2014-07-19 19:05:09
【问题描述】:

我正在尝试将在 WAB 中打包的简单 JSF 应用程序部署到在 Apache Felix OSGI 容器中运行的 Jetty 实例。但是,我不断收到以下异常:

g! May 30, 2014 6:57:31 AM com.sun.faces.spi.InjectionProviderFactory createInstance
WARNING: JSF1033: Resource injection is DISABLED.
May 30, 2014 6:57:31 AM com.sun.faces.config.ConfigureListener contextInitialized
SEVERE: Critical error during deployment: 
java.lang.NoClassDefFoundError: com/sun/faces/spi/InjectionProvider
    at javax.faces.FactoryFinder$FactoryManager.copyInjectionProviderFromFacesContext(FactoryFinder.java:1051)
    at javax.faces.FactoryFinder$FactoryManager.<init>(FactoryFinder.java:1035)
    at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:856)
    at javax.faces.FactoryFinder$FactoryManagerCache.getApplicationFactoryManager(FactoryFinder.java:793)
    at javax.faces.FactoryFinder$FactoryManagerCache.access$100(FactoryFinder.java:768)
    at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:409)
    at com.sun.faces.config.processor.FactoryConfigProcessor.setFactory(FactoryConfigProcessor.java:317)
    at com.sun.faces.config.processor.FactoryConfigProcessor.processFactories(FactoryConfigProcessor.java:259)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:216)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:435)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:446)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:792)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:296)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1359)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1352)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:744)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41)
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498)
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
    at org.eclipse.jetty.osgi.boot.BundleWebAppProvider.bundleAdded(BundleWebAppProvider.java:154)
    at org.eclipse.jetty.osgi.boot.internal.webapp.BundleWatcher.register(BundleWatcher.java:279)
    at org.eclipse.jetty.osgi.boot.internal.webapp.BundleWatcher.addingBundle(BundleWatcher.java:189)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:467)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:414)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:443)
    at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:869)
    at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:790)
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:515)
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4409)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2098)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1297)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.sun.faces.spi.InjectionProvider not  found by javax.faces-api [21]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1550)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1988)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 40 more

这是部署在 OSGI 容器中的捆绑包列表(最后一个是我的应用程序):

START LEVEL 1
ID|State      |Level|Name
0|Active     |    0|System Bundle (4.4.0)
1|Active     |    1|CDI APIs (1.2.0)
2|Active     |    1|Expression Language 3.0 (3.0.0)
3|Active     |    1|Injection API (JSR 330) version 1 repackaged as OSGi bundle (2.2.0)
4|Active     |    1|javax.interceptor API (1.2.0)
5|Active     |    1|Java Servlet API (3.1.0)
6|Active     |    1|JavaServer Pages(TM) API (2.3.1)
7|Active     |    1|Java Server Pages Standard Tag Library API Bundle (1.2.0.v201105211821)
8|Active     |    1|Jetty :: Deployers (9.2.0.M1)
9|Active     |    1|Jetty :: Http Utility (9.2.0.M1)
10|Active     |    1|Jetty :: IO Utility (9.2.0.M1)
11|Resolved   |    1|Jetty JSP Fragment (2.3.3)
12|Active     |    1|Jetty :: OSGi :: Boot (9.2.0.M1)
13|Resolved   |    1|Jetty-OSGi-Jasper Integration (9.2.0.M1)
14|Active     |    1|Jetty Servlet Schemas (3.1.0.M0)
15|Active     |    1|Jetty :: Security (9.2.0.M1)
16|Active     |    1|Jetty :: Server Core (9.2.0.M1)
17|Active     |    1|Jetty :: Servlet Handling (9.2.0.M1)
18|Active     |    1|Jetty :: Utilities (9.2.0.M1)
19|Active     |    1|Jetty :: Webapp Application Support (9.2.0.M1)
20|Active     |    1|Jetty :: XML utilities (9.2.0.M1)
21|Active     |    1|JavaServer Faces API 2.2.6 (20140304-1538) (2.2.0)
22|Active     |    1|Mojarra JSF Implementation 2.2.6 (20140304-1538) (2.2.6)
23|Active     |    1|Apache Felix File Install (3.4.0)
24|Active     |    1|Apache Felix Gogo Command (0.12.0)
25|Active     |    1|Apache Felix Gogo Runtime (0.12.0)
26|Active     |    1|Apache Felix Gogo Shell (0.10.0)
27|Active     |    1|Java Server Pages Standard Tag Library Implementation Bundle provided by Glassfish (1.2.0.v201112081803)
28|Active     |    1|Eclipse Compiler for Java(TM) (3.8.2.v20130121-145325)
29|Active     |    1|osgi.cmpn (5.0.0.201305092017)
30|Active     |    1|jsf-maven-osgi (0.9.0)

应用清单:

Manifest-Version: 1.0
Bundle-SymbolicName: jsf-maven-osgi
Archiver-Version: Plexus Archiver
Built-By: vlada
Bnd-LastModified: 1401425833034
Bundle-ManifestVersion: 2
Import-Package: javax.faces.context;version="[2.2,3)",com.sun.faces.sp
i;version="[2.2,3)",com.sun.faces.config;version="[2.2,3)",com.sun.fa 
 ces.vendor;version="[2.2,3)",javax.faces.webapp;version="[2.2,3)"
Tool: Bnd-2.1.0.20130426-122213
Export-Package: com.vektorsoft.demux.web.jsf;version="0.9.0"
Bundle-Name: jsf-maven-osgi
Bundle-Version: 0.9.0
Web-ContextPath: /hello
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_05

还有 web.xml:

<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<!--    <context-param>
    <param-name>com.sun.faces.injectionProvider</param-name>
    <param-value> com.sun.faces.vendor.WebContainerInjectionProvider</param-value>
</context-param>-->

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>


<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

我想这是某种 OSGI 类路径问题,因为它在部署在非 OSGI Jetty 时工作正常,但我不知道问题出在哪里。似乎我将所有必需的包都导入了 WAB,但仍然没有。 希望有人能告诉我要寻找什么。

【问题讨论】:

    标签: jsf jetty osgi


    【解决方案1】:

    对于 Eclipse 和 tomcat

    1. 停止tomcat服务器
    2. 清理并构建项目
    3. 清理tomcat
    4. 清理tomcat工作目录

    【讨论】:

      【解决方案2】:

      Mojarra 2.x 存在问题。 jsf-api.jar 中的类使用 jsf-impl.jar 中的类,而 jsf-impl.jar 中的许多类使用 jsf-api.jar 中的类。我什至不知道他们是如何编译它们的。

      在这个问题之后,您会遇到 JSF API 找不到很多工厂类的问题。为了解决这个问题,我简单地将 jsf-impl 包作为 jsf-api 的片段。为此,请将以下 MANIFEST 标头添加到 jsf-impl 中:

      Fragment-Host: javax.faces-api
      

      这样,jsf-api 和 jsf-impl 将具有相同的类加载器,因此 jsf-api 将能够初始化所有 Factory 类。我们像这样修补 jsf-impl jar 并在 OSGi 中使用 JSF 好几年了。

      嗯,最近我们决定不再使用 JSF,因为它有很多错误(在概念和实现方面)。

      Mojarra 实现在 wab 中查找 web.xml,并在启动期间自行解析。这意味着如果 JSF servlet 只是使用白板模式或通过 HTTPService 注册,它将无法工作。

      更新:

      我只记得我之前写过一个 Mojarra 2.2 适配器。有关使 JSF 在 OSGi 容器中工作的技巧,请参阅自述文件:https://github.com/everit-org/osgi-mojarrajsf22adapter

      【讨论】:

      • 非常感谢您的回答,现在可以使用了!我唯一的问题是必须自定义 jsf-impl 包的清单。我非常喜欢从 Maven 中按原样使用它。也许我最好使用其他一些 JSF 实现,比如 MyFaces?你有这方面的经验吗?它与 Mojarra 有什么不同?
      • 我没有使用 MyFaces 2.2 的经验。由于 Mojarra 2.2 早在发布之前,我就在 OSGi 中使用了 Mojarra。在 JSF 2.2 之前,我们也使用了 Myfaces 和 mojarra。 Myfaces 更加严格,所以如果我们想从 Mojarra 迁移到 JSF,我们必须正常修复一些拼写错误。 Myfaces 在 OSGi 中运行良好,速度提高了 30-40%。在 Myfaces 2.2 出现之前,我们停止使用 JSF,因为它在实现和概念方面存在许多问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多