0

我无法让 Spring-Web 工作。

  1. 我的 pom.xml 依赖于 spring-web 和 spring-webmvc。
  2. 我的 web.xml 有<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  3. applicationContext.xml 定义了一个 bean “测试”
  4. 我的 index.jsp 尝试通过 RequestContextUtils.getWebApplicationContext(request); 获取上下文

但我得到了一个例外:

java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet request?
    at org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:83)
    at org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:60)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:722)

这是我完整的 web.xml

<?xml version="1.0"?>
<web-app version="3.0">
  <listeners>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listeners>
</web-app>
4

1 回答 1

0
  1. 像@Jaiwo99 sais 一样摆脱 spring-mvc。Spring-Web 在没有 Spring-MVC 的情况下工作得很好。
  2. 使用WebApplicationContextUtils.getWebApplicationContext(application) 而不是 RequestContextUtils.getWebApplicationContext(request).
于 2013-05-13T10:55:23.963 回答