在同一个项目中同时使用EL 1.2和2.2语法(el-api-2.2。)(与使用1.2共存的JSP和使用2.2的JSF共存)

时间:2012-07-25 02:49:59

标签: spring jsf java-ee maven el

我对项目有一个特殊问题,我在项目中使用了两个版本的el-impl jar;我正在使用v1.2来管理我的jsp和2.2管理我的JSF文件,我想要一个解决方案来共存这两个版本因为我需要我的jsp和我的jsf文件

问题是,当我添加关于param-context的EL 2.2时,jsp不起作用,我得到这个例外,因为jsp文件不能与2.2版本一起使用:

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.

当我删除与param-context相关的EL 2.2时,我的意思是来自web.xml的这部分:

 <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>

如果删除,则不支持el-impl2.2,因此当我访问JSF文件时,我得到此异常(因为我没有支持2.2版本)

    org.apache.el.parser.ParseException: Encountered " "(" "( "" at line 1, column 20.
    Was expecting one of:
        "}" ...
        "." ...
        "[" ...
        ">" ...
        "gt" ...
        "<" ...
        "lt" ...
        ">=" ...
        "ge" ...

    ...


Jul 25, 2012 5:39:24 PM com.sun.faces.lifecycle.ELResolverInitPhaseListener populateFacesELResolverForJsp
INFO: JSF1027: [null] The ELResolvers for JSF were not registered with the JSP container

有人可以帮我解决将两个EL jar放在同一个项目中的问题,以便让我用包含JSP和JSF文件来竞争我的项目,就像我使用Maven一样,所以这里是我的依赖项的一部分:

<dependency>
      <groupId>org.glassfish.web</groupId>
      <artifactId>el-impl</artifactId>
      <version>2.2</version>
        <scope>provided</scope>
     </dependency> 

      <dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency> 
<dependency>
          <groupId>com.sun.faces</groupId>
          <artifactId>jsf-api</artifactId>
          <version>2.1.6</version>
        </dependency>
      <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
          <groupId>com.sun.faces</groupId>
          <artifactId>jsf-impl</artifactId>
          <version>2.1.6</version>
        </dependency>

我的web.xml的一部分:

  <?xml version="1.0" encoding="UTF-8"?>
    <web-app 
        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"
        version="2.5">


        <filter>
                <filter-name>springSecurityFilterChain</filter-name>
                <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>

        <filter-mapping>
                <filter-name>springSecurityFilterChain</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
            /WEB-INF/spring-security.xml
            /WEB-INF

    /applicationContext.xml
                </param-value>
            </context-param>


            <context-param>     
            <param-name>com.sun

.faces.expressionFactory</param-name>
        <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
    </context-param>

        <!--  to enable Spring MVC we need to add in this web.xml: -->
        <servlet>
            <servlet-name>spring</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>

        <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>spring</servlet-name>
            <url-pattern>/me/*</url-pattern>
        </servlet-mapping>

        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
            <listener>
            <listener-class>
                org.springframework.web.context.request.RequestContextListener
            </listener-class>
          </listener>

        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.jsf</url-pattern>
          </servlet-mapping>
          <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.faces</url-pattern>
          </servlet-mapping>


        <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
     </servlet-mapping>
    </web-app>

faces-config.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">

    <!-- JSF and Spring are integrated -->

    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>

</faces-config>

我也在使用瓷砖,如果这会导致任何问题,请告诉我,和 感谢您帮助我

1 个答案:

答案 0 :(得分:0)

这绝不可能。

但是,您可以在两个单独的项目中运行它们,但直接在项目中包含相应的EL jar,并从servlet容器lib文件夹中删除servlet容器的预打包EL jar。这至少允许两个应用程序在相同的Web容器,服务器,DNS名称和端口号上运行。