500 java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet req

 上面是浏览器报错,下面是idel报的
20-Oct-2022 19:07:38.611 严重 [http-nio-80-exec-27] org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag No WebApplicationContext found: not in a DispatcherServlet request and no ContextLoaderListener registered?
 java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet request and no ContextLoaderListener registered?
    at org.springframework.web.servlet.support.RequestContext.<init>(RequestContext.java:219)
    at org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java:63) 省略后面。。。。

把问号前面翻译过来就是:(且未注册ContextLoaderListener?)

org.springframework.web.servlet.tags.RequestContextAwareTag。doStartTag未找到WebApplicationContext:未在DispatcherServlet请求中,且未注册ContextLoaderListener?

然后就查了怎么 注册ContextLoaderListener

找到了如下代码:(写在web.xml 里面)
   

 <!-- contextConfigLocation参数用来指定Spring的配置文件 needed for ContextLoaderListener -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:springmvc-servlet.xml</param-value>
  </context-param>

  <!-- 配置spring核心监听器 Bootstraps the root web application context before servlet initialization -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

这时运行起来 已经可以了,但是<web-app>标签红色波浪 也不影响咯 有知道的小伙伴吗 求告知!

完整xml如下

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>

    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>

  </servlet>

  <!-- contextConfigLocation参数用来指定Spring的配置文件 needed for ContextLoaderListener -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:springmvc-servlet.xml</param-value>
  </context-param>

  <!-- 配置spring核心监听器 Bootstraps the root web application context before servlet initialization -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值