dispather-servlet和mvc:资源冲突错误:[0]没有匹配常量

时间:2015-10-13 16:44:40

标签: java spring spring-mvc resources

我几个小时以来一直在阅读与此主题相关的所有问题,但我没有找到解决问题的方法。我的春季版本是4.2.1版本。

的web.xml:

        <div class="row fluid">
            <div class="col-md-3 clearfix">
                    <img src="img">
                    <div class="img-text"> 
                        Tekst fdskfjsdghdfn ufghdg ufdhs gdfksjhg 
                      jfdksgbfjdsk gfd jgbdfjhg dfkjhg fidughdf kjvhdf ugdfh 
                </div>
            </div>
            <div class="col-md-3 clearfix">
                    <img src="img">
                    <div class="img-text"> 
                        Tekst fdskfjsdghdfn ufghdg ufdhs gdfksjhg 
                      jfdksgbfjdsk gfd jgbdfjhg dfkjhg fidughdf kjvhdf ugdfh 
                </div>
            </div>
            <div class="col-md-3 clearfix">
                    <img src="img">
                    <div class="img-text"> 
                        Tekst fdskfjsdghdfn ufghdg ufdhs gdfksjhg 
                      jfdksgbfjdsk gfd jgbdfjhg dfkjhg fidughdf kjvhdf ugdfh 
                </div>
            </div>
            <div class="col-md-3 clearfix">
                    <img src="img">
                    <div class="img-text"> 
                        Tekst fdskfjsdghdfn ufghdg ufdhs gdfksjhg 
                      jfdksgbfjdsk gfd jgbdfjhg dfkjhg fidughdf kjvhdf ugdfh 
                </div>
            </div>
        </div>

applicatinContext.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>
...

dispather-servlet.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" />

com.my.controller.IndexController.java

<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" />

我希望我的控制器位于我的应用程序的根目录中(localhost:8084 / MyApp /)。我的IndexController工作正常,但我的资源没有! 例如,当我请求图像(localhost:8084 / MyApp / img / img.png)时,我遇到了这个错误:

@Controller
public class IndexController {

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

有根本原因:

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

1 个答案:

答案 0 :(得分:0)

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

我将其从4.2.1降级到4.1.7以使其消失。它工作正常!!!!!

请参阅this question