开发者

java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext

I am deploying Portlets on Liferay 5.2.3 on Tomcat 6. I get this error only for one of the portlet.

 java.lang.IllegalStateException: Root context attribute is not of开发者_开发百科 type WebApplicationContext

I did some research and found out that Spring was instantiating a portlet application context when it need a web one. But in my web.xml I am only defining contextLoaderListner

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

And to top it off, if a different *.jar file was being looked up by Spring, then why would my other portlets get deployed except one?

After couple of redeployments I get that to a fix. Can someone put some light on?


The root cause seems to be a static variable in the portal/application server "hanging onto" an instance of a class from the portlet. Two common culprits are log4j and java logging, both of which are commonly used by application containters.

See log4j and the thread context classloader and http://logback.qos.ch/manual/loggingSeparation.html for more discussion of loggers. The suggestion is to use SLF4J with logback OR to be sure to put log4j.jar in your WAR file so it is in the right classloader (although some containers will thwart this solution).

Also, some other class that is present in the container may be the cause. Logging is just a common problem.


Sounds like you are not defining the contextConfigLocation? in web.xml you should also have something like this in addition to the 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>

Where applicationContext.xml is a normal config file for a webapp.

You should also have this in your web.xml if using spring portlet MVC:

<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>

In your portlet.xml I guess you have something like this to specify your portlets:

<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>

If you haven't already, see the spring portlet mvc reference documentation

Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜