Java.lang.IllegalStateException: the root context attribute is not of type WebApplicationContext

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

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

I did some research and found out that Spring was instantiating the portlet application context when it needed a web interface. But in my web.xml I only define contextLoaderListner

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

And for this to happen if another * .jar file was viewed using Spring, why would my other portlets be deployed besides one?

After several redistributions, I get this before the fix. Can someone turn on the lights?

+6
spring model-view-controller listener portlet
source share
2 answers

The root cause seems to be a static variable on the portal / application server that the class instance from the portlet hangs. The two common culprits are log4j and java logging, which are commonly used in applications.

See log4j and the thread context class loader and http://logback.qos.ch/manual/loggingSeparation.html for a more discussion of registrars. The suggestion is to use SLF4J with logic or, of course, put log4j.jar in your WAR file so that it is in the correct classloader (although some containers will prevent this solution).

In addition, the reason may be another class present in the container. Registration is a common problem.

+1
source share

Looks like you are not defining contextConfigLocation? in web.xml you should also have something like this in addition to 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 the usual configuration file for webapp.

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

 <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 assume that you have something like this to indicate 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 have not already done so, see the spring portlet mvc link documentation

Hope this helps.

0
source share

All Articles