3

I configured a specific folder (c:\data\cache\<html files>) to be served statically by Spring Boot like this:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("cache/**")
            .addResourceLocations("file:data/cache/");
}

These HTML files are being served well. The problem is the encoding. They're properly saved (as Windows-1252 - downloaded from a website). When I open them directly from disk in browser they're fine. But when Spring Boot serves them, it forces UTF-8.

I saw a solution to change that - it works - but it changes the encoding to UTF-8 for every HTML:

@Override
public void customize(ConfigurableEmbeddedServletContainer factory) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    mappings.add("html", "text/html;charset=windows-1252");
    factory.setMimeMappings(mappings);
}

But then my regular non-static pages gets served as Windows-1252. So I have to choose one or the other.

Is there any way to tell Spring to serve the static HTML "as is" (or manually specify the encoding)?

Thanks

Luís Soares
  • 5,726
  • 4
  • 39
  • 66
  • You might need to set the encoding for maven in Pom.xml .More over here http://stackoverflow.com/questions/5928046/spring-mvc-utf-8-encoding – Rengas Jul 14 '16 at 23:20
  • hmm that seems a global property.. does not seem something to affect my static HTML only apart from my regular dynamic views... but it can work if I force everything to the static encoding Windows-1252, which is not ideal.. but can help. thx – Luís Soares Jul 14 '16 at 23:23

0 Answers0