开发者

JSF 2 error "Unable to instantiate ExpressionFactory" on App Engine

开发者 https://www.devze.com 2023-03-11 12:45 出处:网络
With a new JSF 2.0 app created in NetBeans 6.9.1 this error message appears in the log file on startup on the production server:

With a new JSF 2.0 app created in NetBeans 6.9.1 this error message appears in the log file on startup on the production server:

com.sun.faces.config.ConfigureListener contextInitialized: Initializing Mojarra 2.0.2 (FCS b10) for context ''

com.sun.faces.spi.InjectionProviderFactory createInstance: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.

> com.sun.faces.config.ConfigureListener installExpressionFactory: Unable to instantiate ExpressionFactory 'com.sun.el.ExpressionFactoryImpl'

Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@7616ad{/,/base/data/home/apps/scroogedemo/1.350894485313261302} com.sun.faces.config.ConfigurationException: It appears the JSP version of the container is older than 2.1 and unable to locate the EL RI expression factory, com.sun.el.ExpressionFactoryImpl. If not using JSP or the EL RI, make sure the context initialization parameter, com.sun.faces.expressionFactory, is properly set. at com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:638)

The app uses the JSF 2.0 reference implementation provided by NetBeans, which seems to include the EL RI (package javax.faces.el).

The application runs fine in the development server. I use these configuration entries in web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    ...
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server<开发者_如何学Go/param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.enableThreading</param-name>
        <param-value>false</param-value>
    </context-param>

I checked the page https://sites.google.com/a/wildstartech.com/adventures-in-java/Java-Platform-Enterprise-Edition/JavaServer-Faces/sun-javaserver-faces-reference-implementation/configuring-jsf-20-to-run-on-the-google-appengine/javaserverfaces-20-and-google-app-engine-compatibility-issues for information on this error but this problem is not covered there.

Update: the page mentioned above said that the el-api and el-impl files need to be included in the project. They are not in the NetBeans libraries list, so they have not been uploaded in the server deployment procedure. I guess they are provided by the local development server - but missing on the production GAE. It turned out to be the solution, see below.


Deploying the app with el-api-2.2.jar and el-impl-2.2.jar solved the problem.


just add this:

    public ServletContextInitializer servletContextInitializer() {
          .....

            sc.setInitParameter("com.sun.faces.expressionFactory", "org.apache.el.ExpressionFactoryImpl");
          .....
}
0

精彩评论

暂无评论...
验证码 换一张
取 消