无法解析名称为Y的servlet中名称为X的视图

弗洛林

我正在将Spring和AngularJS用于其余的Web应用程序。基于教程,并基于教程,我创建了以下文件夹结构:

-src
|----main
    |----webapp
        |----static
            |----api
            |----assets
            |----resources
            |----sections
            |----services
            |----index.html
        |----WEB-INF
            |----web.xml
            |----spring
                |----dispatcher-servlet.xml
                |----applicationContext.xml

我想提供静态HTML文件,因此我将资源声明如下:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="org.tools.mvc.controllers"></context:component-scan>
<mvc:resources location="/static/" mapping="/**"/>
<mvc:resources location="/static/api/" mapping="/api/**"/>
<mvc:resources location="/static/assets/" mapping="/assets/**"/>
<mvc:resources location="/static/resources/" mapping="/resources/**"/>
<mvc:resources location="/static/services/" mapping="/services/**"/>
<mvc:resources location="/static/sections/home/" mapping="/sections/home/**"/>


<bean name="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"></bean>
<bean name="jsonTemplate" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"></bean>

我的问题是,当我部署应用程序(我正在使用Glassfish服务器)时,会发生以下错误(在Eclipse控制台以及浏览器页面中):

2016-05-27T04:46:06.640-0700|Warning: StandardWrapperValve[dispatcher]: Servlet.service() for servlet dispatcher threw exception
javax.servlet.ServletException: Could not resolve view with name 'index.html' in servlet with name 'dispatcher'

该服务的功能不受影响(使用Postman测试其余api成功)。到目前为止,为了进一步开发该应用程序,我手动将index.html添加到URL的末尾(例如localhost:8080 / status / index.html)。在Web Deployment Assembly中声明的“ /”的来源是:

来源:/ src / main / webapp

部署路径:/

更新:web.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>status</display-name>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

如何解决此错误?

谢谢

PS在SO上找到的解决方案不适用于我的方案。

弗洛林

我发现我已经在applicationContext.xml中声明了一个视图解析器(BeanNameViewResolver)。删除视图解析器后,我没有收到错误。

发生错误是因为Spring试图将我的视图(女巫是一个html静态文件)解释为bean。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法在名称为“ dispatcherServlet”的servlet中解析名称为“ forward:/index.html”的视图

无法在名称为“ spring”的servlet中解析名称为“ streamrecords”的视图

Java,Spring,Apache Tiles错误:无法在名称为“ dispatcher”的servlet中解析名称为“ index”的视图

ils。无法在名称为“ grailsDispatcherServlet”的servlet中解析名称为“ index”的视图

Spring Mvc Java无法在名称为'dispatcher'的servlet中解析名称为'home'的视图

无法在名称为'grailsDispatcherServlet'的servlet中解析名称为'/ hello / index'的视图

javax.servlet.ServletException:无法解析名称为“NA-dispatcher”的servlet中名称为“login”的视图

在Spring Boot中无法解析名称为'index'的视图

EnableWebMvc引发ServletException:无法解析名称为的视图

Spring Security抛出javax.servlet.ServletException:无法解析名称为'j_spring_security_check'的视图

在Linux中无法复制名称为“ $”的文件

找不到名称/名称为X的资源

名称为appServlet-servlet.xml的问题

找不到名称为“ ARTShape”的视图组件

无法从Redshift读取名称为空格的列中的数据

无法更新名称为“ routing”的列

'角色名称为X的RelatedEnd已加载

我的快速应用程序中的mongoose.connect的名称为:MongoParserError,消息:“ URI格式错误,无法解析”

名称为空的文件

互动EventTrigger中的事件名称为空

从名称为“.”的 XML 文件中获取节点

创建名称为bean的错误:自动连接的依赖项注入失败,无法解析占位符

无法解析配置':app:_debugApk'的所有依赖项。找不到名称为'default'的配置

点图/ Ggplot与Pandas DataFrame; 列名称为x值,相应的列值为y值

如何在名称为会话变量的视图上显示图像?

如何在Go中解析字段名称为值的JSON?

字段名称为unknowm时解析jsonObject

PowerShell:使用名称为“ ADDRESS”的XML进行解析

解析JSON数组BEGIN_ARRAY,但名称为