java.lang.IllegalStateException:根上下文属性不是WebApplicationContext类型

Som*_*Guy 7 model-view-controller spring portlet listener

我正在Tomcat 6上的Liferay 5.2.3上部署Portlets.我只为其中一个portlet收到此错误.

 java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext
Run Code Online (Sandbox Code Playgroud)

我做了一些研究,发现Spring在需要web时实例化portlet应用程序上下文.但在我的web.xml中,我只定义了contextLoaderListner

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

最重要的是,如果Spring正在查找不同的*.jar文件,为什么我的其他portlet会被部署,除了一个?

经过几次重新部署后,我得到了解决方案.有人能说点什么吗?

小智 0

听起来您没有定义 contextConfigLocation ?在 web.xml 中,除了 contextLoaderListener 之外,还应该有类似的内容:

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

</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

其中 applicationContext.xml 是 Web 应用程序的普通配置文件。

如果使用 spring portlet MVC,您还应该在 web.xml 中包含以下内容:

<servlet>
    <servlet-name>ViewRendererServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>ViewRendererServlet</servlet-name>
    <url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

在您的 portlet.xml 中,我猜您有类似的内容来指定您的 portlet:

<portlet>
<portlet-name>sample</portlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<supports>
    <mime-type>text/html</mime-type>
    <portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
    <title>Sample Portlet</title>
</portlet-info>
</portlet>
Run Code Online (Sandbox Code Playgroud)

如果您还没有,请参阅 spring portlet mvc 参考文档

希望能帮助到你。