Spring Boot: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

Spring Boot: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

could not resolve view with name '/index' in servlet with name 'grailsdispatcherservlet
spring-boot view not found
could not resolve view with name thymeleaf
spring boot view resolver
spring boot mvc
webflux java lang illegalstateexception could not resolve view with name
spring mvc with jsp view
how to use view in spring boot

I am trying to set home page of my application by using spring boot.. but I am getting the error as Could not resolve view with name 'index.html' in servlet with name 'dispatcherServlet'

My code is as follow

RunApplication.java

@SpringBootApplication
public class RunApplication {

    static Logger logger = Logger.getLogger(RunNavneetApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(RunNavneetApplication.class, args);
    }
}

application.properties

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.html

HomeController.java

@Controller 
public class HomeController {
    @RequestMapping("/")
    public String index() {
        return "index";
    }
}

WebConfig.java

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/productImages/**")
        .addResourceLocations("file:/home/rahul/Desktop/product_images/")
        .setCachePeriod(0);
    }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wocs</groupId>
  <artifactId>REST</artifactId>
  <version>0.0.1-SNAPSHOT</version>


<properties>
<java-version>1.8</java-version>
<service-version>0.1.36-SNAPSHOT</service-version>
</properties>  

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
  </parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
          <groupId>com.wocs</groupId>
          <artifactId>services</artifactId>
          <version>${service-version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

</dependencies>

Please help me to fix this issue.. Thanks a lot in advance...


For me (spring-boot-starter-parent version 2.0.5.RELEASE) it worked changing the path in this way:

src/main/resources/WEB-INF/view/index.htmlsrc/main/resources/META-INF/resources/view/index.html (for some reason it seemed not liking the WEB-INF name and it needed the nested resources directory).

It seems to work also with src/main/resources/resources/view/index.html

In these cases you don't even need to add the @EnableWebMvc annotation and implement the WebMvcConfigurer (prefix and suffix configured in application.properties are enough).

I add to my answer also a clarification about the MVC configuration taken from the Spring Boot Reference Guide:

27.1.1 Spring MVC Auto-configuration

If you want to keep Spring Boot MVC features and you want to add additional MVC configuration [...] you can add your own @Configuration class of type WebMvcConfigurer but without @EnableWebMvc.

If you want to take complete control of Spring MVC, you can add your own @Configuration annotated with @EnableWebMvc.

76.7 Switch off the Default MVC Configuration

The easiest way to take complete control over MVC configuration is to provide your own @Configuration with the @EnableWebMvc annotation. Doing so leaves all MVC configuration in your hands.

Could not resolve view with name 'guest-login' in servlet with name , Could not resolve view with name 'guest-login' in servlet with name Spring Boot Admin needs to have access to the /health endpoint. I guess  jsp,spring-mvc,spring-boot There are two things I see wrong. First if your code is really as posted and not a typo, than you should note that you don't print anything inside a loop as you just iterate and never do anything with the user variable The following <c:forEach items = "${tweets}" var="user"


In your code you have defined suffix and prefix

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.html

So all page in your request will convert to html file automatically,so you need to change return "index.html"; to return "index";

Change to

@Controller 
public class HomeController {
    @RequestMapping("/")
    public String index() {
        return "index";
    }
}

Could not resolve view with name 'xxxx' in servlet with name 'yyyy , In general, STS is Eclipse with the Spring Tools extensions pre-installed (plus a few extra third-party plugins that we find useful). So that doesn't  Could not resolve view with name 'redirect: I had same Issue, as I understand @EnableWebMvc is not needed in Spring Boot 2.2.4. I removed it, and everything works


I was getting this error when doing a CURL request in my spring boot application:

{"timestamp":1566549840380,"status":500,"error":"Internal Server Error","message":"Could not resolve view with name 'createApiKey' in servlet with name 'dispatcherServlet'","path":"/createApiKey"}

I fixed it by changing from @Controller to @RestController (which is a combination of @Controller and @ResponseBody) like this:

@RestController
public class ApiKeyController {
    ...
    @GetMapping("/createApiKey")
    public DeferredResult<CreateApiKeyResp> createApiKey(@RequestParam long userId) {
        ...

I can't find answer that Could not resolve view with name 'index' in , Spring boot Could not resolve view with name 'index' in servlet with name '​dispatcherServlet'. Here's my spring boot configuration. Could not resolve view with name 'guest-login' in servlet with name 'dispatcherServlet' #813 Closed Mike-the-one opened this issue Jul 5, 2018 · 5 comments


Spring boot Could not resolve view with name 'index' in , ServletExceptionCould not resolve view with name '/index' in servlet with name https://github.com/codecentric/spring-boot-admin/issues/813. Could not  As a fix ,in pom.xml, for spring-boot-starter-tomcat remove tag. It is needed only if its not a spring boot application. It is failing because there is no explicit tomcat server. After fixing this issue also example is not working properly. Suppose I am hiiting localhost:8080/next then response is


javax.servlet.ServletException: Could not resolve view , I decided that Spring MVC on an embedded Tomcat server set up using Spring Boot is just what I need. I want to use Thymeleaf as view technology, and therefore  Spring WebFlux doesn't handle redirect: directives when media type is Could not resolve view with name 'redirect:/'. I've just tested this against Spring Boot


Could not resolve view with name 'htmlviews/index.html' in servlet , javax.servlet.ServletException: Could not resolve view with name home-- apache Velocity, spring. Post by: vineet bindal , Greenhorn. Aug 29, 2011 15:25:35. Hi, If thats the case you need to set up the x-forward headers correctly and enable that behavior in spring boot. If you are running a boot app but elected to configure the web application yourself, either by @EnableWebMvc annotation or implementing WebMvcConfigurationSupport , then you need to configure your swagger-ui on your own (add resource handlers).