2013-07-31 5 views
0

내 webapp의 평생 버전을 6.1.0에서 6.1.1 (6.1.1-ga2 버전을 liferay patchers community에서 사용)으로 마이그레이션하는 중입니다. 이전에 작업. Spring DispatcherServlet 컨텍스트 인스턴스 생성 오류 (liferay) 6.1.1

나는 스프링의 DispatcherServlet의 인스턴스를 PortalDelegateServlet를 사용하는 것이 내 웹 서비스에 문제가 있습니다.

내가 가진 문제는 내 서블릿 (myWS-servlet.xml 파일)의 스프링 컨텍스트 전에 인스턴스화 때문이다 PortletContextLoaderListener의 응용 프로그램 컨텍스트 (스프링으로도 ContextLoaderListener과 같은 시도) 및 내 컨트롤러 u (DispatcherServlet이 인스턴스화 될 때로드되지 않은) 주요 응용 프로그램 컨텍스트에서 서비스를 실행하면 봄에 자동 실행되지 않습니다.

이상한 점은 포틀릿을 재배포하면 문제가 해결된다는 것입니다.

어떻게 해결할 수 있습니까?


내 web.xml을

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
<display-name>banner-portlet</display-name> 
<jsp-config> 
    <taglib> 
     <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri> 
     <taglib-location>/WEB-INF/tlds/liferay-portlet.tld</taglib-location> 
    </taglib> 
    <taglib> 
     <taglib-uri>http://liferay.com/tld/theme</taglib-uri> 
     <taglib-location>/WEB-INF/tlds/liferay-theme.tld</taglib-location> 
    </taglib> 
    <taglib> 
     <taglib-uri>http://liferay.com/tld/portlet</taglib-uri> 
     <taglib-location>/WEB-INF/tlds/liferay-portlet-ext.tld</taglib-location> 
    </taglib> 
</jsp-config> 

<servlet> 
    <servlet-name>liferayWSdispatcher</servlet-name> 
    <servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class> 
    <init-param> 
     <param-name>servlet-class</param-name> 
     <param-value>org.springframework.web.servlet.DispatcherServlet</param-value> 
    </init-param> 
    <init-param> 
     <param-name>sub-context</param-name> 
     <param-value>rest-api</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>liferayWSdispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

<listener> 
    <listener-class>com.liferay.portal.spring.context.PortletContextLoaderListener</listener-class> 
</listener> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:applicationContext.xml</param-value> 
</context-param> 

<context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</param-value> 
</context-param> 
<context-param> 
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> 
    <param-value>true</param-value> 
</context-param> 
<!-- Instruct Mojarra to utilize JBoss-EL instead of the EL implementation 
    provided by the servlet container. --> 
<!-- was used only for admin portlets but make calendar portlet crash 
<context-param> 
    <param-name>com.sun.faces.expressionFactory</param-name> 
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value> 
</context-param> 
--> 
<servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<filter> 
    <filter-name>PrimeFaces FileUpload Filter</filter-name> 
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>PrimeFaces FileUpload Filter</filter-name> 
    <servlet-name>Faces Servlet</servlet-name> 
</filter-mapping> 

<listener> 
    <listener-class>com.liferay.faces.portal.listener.StartupListener</listener-class> 
</listener> 


<!-- MyFaces will not initialize unless a servlet-mapping to the Faces Servlet 
    is present. --> 
<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern> 
</servlet-mapping> 



<context-param> 
    <param-name>portalContextConfigLocation</param-name> 
    <param-value>/WEB-INF/applicationContext-velocity-tool.xml</param-value> 
</context-param> 

내 applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

<context:component-scan base-package="be.maximede"> 
    <context:exclude-filter type="regex" expression="be.maximede.webservice.*"/> 
</context:component-scan> 

내 myWS-servlet.xml에

,536
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

<context:component-scan base-package="be.maximede.webservice"/> 

<mvc:annotation-driven /> 
을 Liferay 6.1.1이있는 알려진 문제에 대한

답변

3

나는이 스레드가 세 이상 알고있다. 하지만 나는 사람들에게 어떤 문제를 덜어주기를 원했습니다. 동료들과 저는 스프링과 PortalDelegateServlet + DispatcherServlet을 사용하는 포틀릿 컨트롤러 전에 스프링 서비스를로드 할 수없는 이유를 파악하기 위해 일주일을 보냈습니다.

다른 포스터가 댓글을 달았 기 때문에 다소 문제는 있지만 http://issues.liferay.com/browse/LPS-29103 호와 직접 관련이 없습니다. Servlet이 liferay에서 초기화되는 방식과 Liferay가 web.xml 재 작성을 처리하는 방식과 관련이 있습니다.

을 Liferay는 web.xml에 내에서 정의 된 모든 청취자를 재 작성하고 상황에 맞는 PARAM로두고이 추천했습니다 :

<context-param> 
    <param-name>portalListenerClasses</param-name> 
    <param-value>com.liferay.portal.kernel.servlet.SerializableSessionAttributeListener,org.springframework.web.context.ContextLoaderListener</param-value> 
</context-param> 

을 한 후 자신의 리스너를 만듭니다 (도시 아닌지하는 PluginContextListener) :

<listener> 
    <listener-class>com.liferay.portal.kernel.servlet.SecurePluginContextListener</listener-class> 
</listener> 

이 SecurePluginContextListener는 컨텍스트를로드하고 연결합니다. 문제는 때로는 SecurePluginContextListener가 먼저 웹 응용 프로그램 컨텍스트로 PortalDelegateServlet을 초기화 한 다음 portalListenerClasses 내의 init 메서드로 이동한다는 것입니다. 따라서 포틀릿 컨트롤러 내의 모든 AutoWired 항목에는 모든 종속성 (응용 프로그램 컨텍스트의 서비스)이 누락되었습니다.

이 문제를 해결하기 위해 web.xml에서 PortalDelegateServlet 선언을 버리고 PortalDelagateServlet 및 ServletConfig를 새로 작성하여 Spring의 DispatcherServlet에 동일한 매개 변수를 전달하는 사용자 정의 ServletContextListener를 만들었습니다. 이것이 작동하는 이유는 Liferay가 portalListenerClasses 내에서 모든로드를 수행하도록하기 때문입니다. 다시 작성된 web.xml은 다음과 같습니다.

<context-param> 
    <param-name>portalListenerClasses</param-name> 
    <param-value>com.liferay.portal.kernel.servlet.SerializableSessionAttributeListener,org.springframework.web.context.ContextLoaderListener, com.domain.CustomContextListener</param-value> 
</context-param> 

그리고 CustomContextListener는 ServletContextListener에 메소드를 구현합니다. CustomContextListener의 contextInitialized (...) 메소드 내에서 우리는 web.xml 내에서 동일한 ServletConfig (ServletConfig를 구현하는 내부 클래스)를 프로그래밍 방식으로 만들었습니다. 그런 다음 pds = new PortalDelegateServlet()을 작성하고 pds.init (customServletConfig)를 호출하십시오.

+0

감사! 내 문제가 해결 됐어! 프로덕션 환경에서 이중 배포가 필요 없음) – maximede

+0

안녕하세요, CustomContextListener 및 CustomServletConfig 클래스 구현을 게시 할 수 있습니까? 그들에게 행운이 없다. 고맙습니다. – jbub

관련 문제