自定义ContextLoaderListener类在Websphere中不起作用,并引发以下错误。在Tomcat,JBoss和Weblogic中也可以正常工作。
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
我的自定义上下文加载器类如下所示:
public class CustomContextListener extends ContextLoaderListener {
//implemented contextInitized() and contextDestroyed() methods
}
在web.xml中,添加如下:
<listener>
<listener-class>com.comp.app.context.CustomContextListener</listener-class>
</listener>
有人可以帮助我解决此错误吗?
更新:在日志中发现以下错误。
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)}
最佳答案
ContextLoaderListener
的全部要点是它的contextInitialized()
方法,用于在WebApplicationContext
中初始化和注册ServletContext
。如果您在未调用super
实现的情况下重写了此方法,则它将不会注册任何WebApplicationContext
。