繁体   English   中英

没有视图解析器但纯HTML的Spring

[英]Spring with no view resolver but plain html

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

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

这是我的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:

<?xml version="1.0" encoding="UTF-8"?>

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

<!-- The definition of the Root Spring Container shared by all Servlets 
    and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>

    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>/WEB-INF/views/index.html</welcome-file>
</welcome-file-list> 

我知道这是一个比较老的问题,所以这是给现在来这里的人的。 只要文件路径正确,Spring就会自动配置为获取您的视图,因此您不必进行任何spring webmvc configuration

我在Intellij中遇到了这个问题,只需要重新启动应用程序,错误就消失了。 希望有人看到这个并且不会花很多时间在此上。

这个错误

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

这显然没有意义。

如果你想

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

将欢迎文件添加到您的部署描述符。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM