上面是浏览器报错,下面是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>