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

标签 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)}

最佳答案

ContextLoaderListener 的重点在于其 contextInitialized() 方法在 ServletContext 中初始化和注册 WebApplicationContext 。如果您重写了此方法而不调用 super 实现,则它将不会注册任何 WebApplicationContext

关于java - 自定义 ContextLoaderListener 类在 Websphere 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20811960/

相关文章:

java - Spring Maven DispatcherServlet noHandlerFound

angularjs - 在 Spring Security 或 Angular 中注销时清除 Cookie

spring - 以编程方式控制 @RestController 可用性

java - Hibernate 似乎从 HQL 查询创建了错误的 SQL 查询

java - Hibernate + spring 版本兼容性

spring - 在 Spring Security OAuth 中,您如何将 passwordEncoder 用于客户端 secret ?

mysql - org.springframework.web.multipart.MultipartException : Current request is not a multipart request

java - 如何创建多模块 spring mvc 应用程序

使用 HttpsUrlConnection 的 Java POST 连接超时

java - 它的用途 <sf :errors path ="" cssClass ="error"> in jsp?