Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 621
Some Java Guy Avatar asked Feb 08 '11 14:02

Some Java Guy


1 Answers

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.

like image 152
M Smith Avatar answered Oct 04 '22 23:10

M Smith