0

I want to host JSON file from project directory, i put a file in src/main/resources/templates/movies1.json. The @GetMapping is shown below.

package com.rameelhashmi.springboot.movies.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class MoviesController {

    // create a mapping for "/hello"

    @GetMapping("/movies1")
    public String MoviesJson() {

        return "movies1";
    }
    @GetMapping("/movies")
    public String Movies1() {

        return "movies";
    }
}

In my HTML code i give the link for JSON file is: $.getJSON("http://localhost:8080/movies1", function(data){

The HTML page does not load the JSON file from directory, But if i change the movies1.json to movies1.html it works perfectly fine. The error in console shows as:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [movies1], template might not exist or might not be accessible by any of the configured Template Resolvers

Psidom
  • 209,562
  • 33
  • 339
  • 356
  • For Thymeleaf, the filename extension should be `.html` so that your controller can return the filename directly. – LHCHIN Nov 07 '19 at 01:39
  • You can refer to [Creating a file download link using Spring Boot and Thymeleaf](https://stackoverflow.com/questions/29816121/creating-a-file-download-link-using-spring-boot-and-thymeleaf) for how to download *movies1.json*. – LHCHIN Nov 07 '19 at 05:07

0 Answers0