zeroklone
zeroklone

Reputation: 1

Thymeleaf and static content

I am working on a Spring Boot project where Thymeleaf is being used as the template engine. I am setting up Swagger on this project, so I want to be able serve static content alongside my Thymeleaf content.

"example.com/help" should return a template.

"example.com/docs" should return static content.

At the moment this:

@RequestMapping("/docs")
    public String index() {
        return "index.html";
    }

returns this:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index.html", template might not exist or might not be accessible by any of the configured Template Resolvers

I don't want Thymeleaf to be resolving this path.

Upvotes: 0

Views: 1327

Answers (1)

sodik
sodik

Reputation: 4683

Simple answer: If you don't want Thymeleaf/Spring MVC to handle your requests, then don't ask for it :)

Longer answer: When you use @RequestMapping in your controller, you usually fill-in some model and tell Spring MVC to use view to render that model (that's where Thymeleaf comes in).

If you want serve static resources, you have to configure it differently. Here is example:

@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
         registry.addResourceHandler("/docs/**").addResourceLocations("file://path/to/yourDocs/");
    }

}

Upvotes: 1

Related Questions