2013-11-04 108 views
1

我使用Eclipse> Liferay Project> Portlet> JSF 2.x> Primefaces創建了一個新項目。然後,我正在嘗試將Spring Bean管理添加到它,通過以下demo

問題在於,當部署到tomcat 7時,生成的portlet引發異常。Liferay和JSF2 + Spring集成

Source Document: jndi:/localhost/jsf-test-portlet/WEB-INF/faces-config.xml Cause: Class 'org.springframework.web.jsf.el.SpringBeanFacesELResolver' is missing a runtime dependency: java.lang.NoClassDefFoundError: org/springframework/beans/factory/access/el/SpringBeanELResolver

如果我查看項目的'lib'目錄,這些jar就位,在生成的WAR中是一樣的。所以我不知道問題可能源於哪裏。


我的ivy.xml

<?xml version="1.0"?> 
<ivy-module 
version="2.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" 
> 
<info module="portlet_primefaces_tmpl" organisation="com.liferay" /> 

<dependencies defaultconf="default"> 
    <dependency name="el-api" org="javax.el" rev="2.2" /> 
    <dependency name="jboss-el" org="org.jboss.el" rev="2.0.1.GA" /> 
    <dependency name="jsf-api" org="com.sun.faces" rev="2.1.21" /> 
    <dependency name="jsf-impl" org="com.sun.faces" rev="2.1.21" /> 
    <dependency name="liferay-faces-bridge-api" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="liferay-faces-bridge-impl" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="liferay-faces-portal" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="liferay-faces-util" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="primefaces" org="org.primefaces" rev="3.5" /> 
    <dependency org="org.springframework" name="spring-core" rev="3.2.1.RELEASE"/> 
    <dependency org="org.springframework" name="spring-web" rev="3.2.1.RELEASE" /> 
</dependencies> 

我的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"> 

<context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</param-value> 
</context-param> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/portlet-context.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> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<listener> 
    <listener-class>org.springframework.web.context.request.RequestContextListener</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> 

<!-- Prevent direct access to Facelet view XHTML by the userAgent (browser). --> 
<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Facelet View XHTML</web-resource-name> 
     <url-pattern>*.xhtml</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>nobody</role-name> 
    </auth-constraint> 
</security-constraint> 
<security-role> 
    <role-name>nobody</role-name> 
</security-role> 

我faces-config.xml中

<?xml version="1.0"?> 
<faces-config version="2.1" 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_1.xsd"> 

<lifecycle> 
    <phase-listener>com.liferay.faces.util.lifecycle.DebugPhaseListener</phase-listener> 
</lifecycle> 
<application> 
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> 
</application> 

+0

如果你下載了[JSF2彈簧的portlet]戰爭(https://www.liferay.com/community/liferay-項目/ liferay-faces /演示#jsf2-spring-portlet)演示並將其部署到您的$ LIFERAY_HOME/deploy文件夾中,然後在您的tomcat環境中工作嗎? –

+0

我做了你的建議,並且它在WAR中完美工作(我可以看到工作申請表)。但在部署時我的問題仍然存在(例外)。 – whyem

回答

0

分析從演示的WAR,我意識到,有7個春節的jar它, 我說那些剩餘的依賴關係,我ivy.xml文件,那麼「乾淨/部署」,現在它的工作。也許並非所有JARS都是必需的,但這是下一步,刪除那些不必要的。

ivy.xml現在看起來是這樣的:

<?xml version="1.0"?> 
<ivy-module 
version="2.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" 
> 

<info module="portlet_primefaces_tmpl" organisation="com.liferay" /> 

<dependencies defaultconf="default"> 
    <dependency name="jboss-el" org="org.jboss.el" rev="2.0.1.GA" /> 
    <dependency name="jsf-api" org="com.sun.faces" rev="2.1.21" /> 
    <dependency name="jsf-impl" org="com.sun.faces" rev="2.1.21" /> 
    <dependency name="liferay-faces-bridge-api" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="liferay-faces-bridge-impl" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="liferay-faces-portal" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="liferay-faces-util" org="com.liferay.faces" rev="3.1.3-ga4" /> 
    <dependency name="primefaces" org="org.primefaces" rev="3.5" /> 
    <!-- Spring dependencies --> 
    <dependency name="spring-core" org="org.springframework" rev="3.0.7.RELEASE"/> 
    <dependency name="spring-web" org="org.springframework" rev="3.0.7.RELEASE" /> 
    <dependency name="spring-context" org="org.springframework" rev="3.0.7.RELEASE" /> 
    <dependency name="spring-beans" org="org.springframework" rev="3.0.7.RELEASE" /> 
    <dependency name="spring-expression" org="org.springframework" rev="3.0.7.RELEASE" /> 
    <dependency name="spring-aop" org="org.springframework" rev="3.0.7.RELEASE" /> 
    <dependency name="spring-asm" org="org.springframework" rev="3.0.7.RELEASE" /> 
</dependencies> 

+0

很高興聽到你有工作:)請注意,jsf2-spring-portlet演示使用Maven來管理依賴關係。 [pom.xml](https://github.com/liferay/liferay-faces/blob/3.1.x/demos/bridge/jsf2-spring-portlet/pom.xml#L41)描述符僅將spring-web引用爲依賴關係。所有其他與Spring相關的JAR依賴都是可傳遞的,因此它們被自動包含在內。常春藤有能力下載/包含傳遞依賴關係,所以我不知道爲什麼你必須單獨列出它們。 –

+0

關於傳遞性依賴關係的有趣提示。我正如問題中所描述的那樣從頭開始創建項目,並且生成的JSF2.X項目隨附IVY。是否有另外一個選項易於設置或像Eclipse/IVY一樣「準備使用」?我真的很喜歡用Maven而不是IVY開發Portlet。 – whyem

+1

新的[Liferay IDE 2.0 M2](https://www.liferay.com/community/wiki//wiki/1071674/Liferay+IDE+1.x+-+2.0+Upgrade+steps)版本可讓您創建Ant + Ivy或Maven的項目。如果你選擇Maven,那麼它會自動知道使用哪個[Liferay Faces Maven Archetype](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.liferay.maven.archetypes%22)來使用。 –