Question

Custom ContextLoaderListener class is not working in Websphere and it is throwing the below error. The same is working fine in Tomcat, JBoss, Weblogic.

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

My custom context loader class looks like below:

public class CustomContextListener extends ContextLoaderListener {
     //implemented contextInitized() and contextDestroyed() methods
}

In web.xml, added as below:

<listener>
  <listener-class>com.comp.app.context.CustomContextListener</listener-class>
</listener>

Can anybody help me to resolve this error?

Update: Found the below error in logs.

 00000026 DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name configMgr: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: xxxx; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [xxxxxx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Was it helpful?

Solution 2

I found the root cause of my problem. Here the problem is not with Custom Context Loader. I have not configured JNDI name properly in my spring application context xml file. Now Custom class is working fine and error is gone.

OTHER TIPS

The whole point of ContextLoaderListener is its contextInitialized() method initializing and registering the WebApplicationContext in the ServletContext. If you have overriden this method without calling the super implementation, it won't register any WebApplicationContext.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top