自定义ContextLoaderListener类在Websphere中不起作用

时间:2013-12-28 06:59:59

标签: java spring spring-mvc websphere web.xml

自定义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)}

2 个答案:

答案 0 :(得分:1)

ContextLoaderListener的重点是contextInitialized()方法初始化并在WebApplicationContext中注册ServletContext。如果您在不调用super实现的情况下覆盖此方法,则不会注册任何WebApplicationContext

答案 1 :(得分:0)

我找到了问题的根本原因。这里的问题不在于Custom Context Loader。我没有在我的spring应用程序上下文xml文件中正确配置JNDI名称。现在Custom类工作正常,错误消失了。

相关问题