Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring没有视图解析器,只有纯html_Java_Spring_Spring Mvc - Fatal编程技术网

Java Spring没有视图解析器,只有纯html

Java Spring没有视图解析器,只有纯html,java,spring,spring-mvc,Java,Spring,Spring Mvc,我试图将Spring配置为仅使用html文件而不是jsp视图解析器,但无法使其工作。我尝试了许多不同的配置,我只想在每次输入localhost:8080/时重定向到/WEB-INF/views/index.html。现在,我的tomcat控制台中有: org.springframework.web.servlet.PageNotFound-未找到的映射 DispatcherServlet中URI为[/WEB-INF/views/index.html]的HTTP请求 名称为“appServlet”

我试图将Spring配置为仅使用html文件而不是jsp视图解析器,但无法使其工作。我尝试了许多不同的配置,我只想在每次输入localhost:8080/时重定向到/WEB-INF/views/index.html。现在,我的tomcat控制台中有:

org.springframework.web.servlet.PageNotFound-未找到的映射 DispatcherServlet中URI为[/WEB-INF/views/index.html]的HTTP请求 名称为“appServlet”

这是我的
servlet context.xml
代码片段

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="WEB-INF/views/" />
    <beans:property name="suffix" value="" />
</beans:bean>
<view-controller path="/" view-name="index.html"/>

有什么建议我遗漏了什么

编辑- web.xml:


http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“>


上下文配置位置
/WEB-INF/spring/root-context.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/appServlet/servlet-context.xml
1.
appServlet
/
/WEB-INF/views/index.html
此错误

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'.
告诉我们你要去以下地址

localhost:8080/WEB-INF/views/index.html
这显然毫无意义

如果你愿意

每次重定向到/WEB-INF/views/index.html localhost:8080/已输入

将欢迎文件添加到部署描述符中

<welcome-file-list>
    <welcome-file>WEB-INF/views/index.html</welcome-file>
</welcome-file-list>

WEB-INF/views/index.html

尝试在前缀中添加/

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value="" />
</beans:bean>
<view-controller path="/" view-name="index.html"/>

我知道这是一个较老的问题,所以这是为现在来到这里的任何人准备的。只要文件路径正确,Spring将自动配置为拾取您的视图,因此您不必执行任何
Spring webmvc配置


我在Intellij中遇到了这个问题,只需重新启动应用程序,错误就消失了。希望有人看到了这一点,不要花几个小时来处理这个问题。

现在我有了
警告:org.springframework.web.servlet.PageNotFound-在名为“appServlet”的DispatcherServlet中找不到URI为[/]的HTTP请求的映射。
:(@xwhyz你的
DispatcherServlet
映射到什么url?当你在它上面时,只需发布你的完整配置。@xwhyz文件
WEB-INF/views/index.html
真的存在于你所说的位置吗?这就是它现在的样子,我有两个index.html“以防万一”@xwhyz为了尝试找到问题,删除你的
声明重新编译并重建您的项目。检查您的servlet上下文配置是否存在可能会干扰的内容不会有什么坏处。
<welcome-file-list>
    <welcome-file>WEB-INF/views/index.html</welcome-file>
</welcome-file-list>
<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value="" />
</beans:bean>
<view-controller path="/" view-name="index.html"/>