gpt4 book ai didi

java - 调度程序 servlet 和 mvc :resources conflict error: No matching constant for [0]

转载 作者:太空宇宙 更新时间:2023-11-04 13:20:29 26 4
gpt4 key购买 nike

我已经阅读了与此主题相关的所有问题几个小时,但我还没有找到解决我的问题的方法。我的 Spring 版本是 4.2.1-release。

web.xml:

...
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/security.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
...

applicatinContext.xml:

<mvc:resources mapping="/lib/**" location="/lib/"/>
<mvc:resources mapping="/img/**" location="/img/" />
<mvc:resources mapping="/app/**" location="/app/" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:annotation-driven />

<context:annotation-config />
<context:component-scan base-package="com.my.controller" />

dispather-servlet.xml:

<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/myview/"
p:suffix=".jsp" />

com.my.controller.IndexController.java

@Controller
public class IndexController {

@RequestMapping(value="/",method = RequestMethod.GET)
public String index(HttpServletRequest request, Model map) {
return "index";
}
}

我希望我的 Controller 位于应用程序的根目录中 (localhost:8084/MyApp/)。我的 IndexController 工作正常,但我的资源却不行!
例如,当我请求图像(localhost:8084/MyApp/img/img.png)时,我遇到此错误:

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: No matching constant for [0]  

根本原因:

java.lang.IllegalArgumentException: No matching constant for [0]
at org.springframework.http.HttpStatus.valueOf(HttpStatus.java:488)
at org.springframework.web.context.request.ServletWebRequest.isCompatibleWithConditionalRequests(ServletWebRequest.java:244)
at org.springframework.web.context.request.ServletWebRequest.checkNotModified(ServletWebRequest.java:181)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:240)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

最佳答案

这似乎是 Spring 最新版本(4.2 和 4.2.1)中的一个错误。

我从 4.2.1 降级到 4.1.7 以使其消失。效果很好!!!!

参见this question .

关于java - 调度程序 servlet 和 mvc :resources conflict error: No matching constant for [0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33108190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com