0
votes

I'm trying to configure Spring to use only my html files instead of jsp view resolver but can't get it to work. I tried many different configurations and I simply want to have redirection to /WEB-INF/views/index.html everytime localhost:8080/ is entered. Now what I have in my tomcat console is:

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'.

here's my servlet-context.xml snippet.

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

Any suggestions what am I missing?

EDIT- 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> 

3

3 Answers

2
votes

I know this is an older question so this is for anyone who comes here now. Spring is auto-configured to pick up your views as long as your file paths are correct, so you should not have to do any spring webmvc configuration.

I ran into this issue in Intellij and simply had to restart the application and the error was gone. Hope someone sees this and doesn't spend hours working on this.

0
votes

This error

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'.

is telling us that you are actually going to the following address

localhost:8080/WEB-INF/views/index.html

which obviously makes no sense.

If you want

to have redirection to /WEB-INF/views/index.html everytime localhost:8080/ is entered

add a welcome file to your deployment descriptor.

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

Try to add a / to the prefix.

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