【问题标题】:Spring Setup not working弹簧设置不起作用
【发布时间】:2013-05-05 02:52:53
【问题描述】:

我无法让 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>

【问题讨论】:

  • 您是否在部署描述符中使用 Springs DispatcherServlet?据我所知,从堆栈跟踪表明您不是,这是让 Spring 在 Web 环境中工作的重要部分。
  • 好吧,你需要:)
  • iv 将 servlet 绑定到 *.jsp,但他喜欢使用 ...-servlet.xml。这是 webmvc 对吗?我可以摆脱 webmvc 并只使用 spring web 吗?
  • 你应该在你的 web.xml 中定义 ...
  • @Jaiwo99 请阅读我最后的评论。

标签: spring jsp web-applications


【解决方案1】:
  1. 像@Jaiwo99 sais 一样摆脱 spring-mvc。没有 Spring-MVC,Spring-Web 也能很好地工作。
  2. 使用WebApplicationContextUtils.getWebApplicationContext(application) 代替 RequestContextUtils.getWebApplicationContext(request).

【讨论】:

  • Session-Beans 和 Request-Beans 必须有第二个 listener-class RequestContextListener
猜你喜欢
  • 2017-09-25
  • 2013-11-29
  • 1970-01-01
  • 2011-01-02
  • 2011-06-22
  • 2014-02-15
  • 1970-01-01
相关资源
最近更新 更多