Skip to content

Instantly share code, notes, and snippets.

@mdeterman
Created April 24, 2017 15:26
Show Gist options
  • Save mdeterman/e67839a7b673148dd5d49876ce8381cb to your computer and use it in GitHub Desktop.
Save mdeterman/e67839a7b673148dd5d49876ce8381cb to your computer and use it in GitHub Desktop.
Spring Config for SAP
@Configuration
@EnableConfigurationProperties({ResourceProperties.class})
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private ResourceProperties resourceProperties = new ResourceProperties();
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
Integer cachePeriod = resourceProperties.getCachePeriod();
final String[] staticLocations = resourceProperties.getStaticLocations();
final String[] indexLocations = new String[staticLocations.length];
for (int i = 0; i < staticLocations.length; i++) {
indexLocations[i] = staticLocations[i] + "index.html";
}
registry.addResourceHandler(
"/**/*.css",
"/**/*.html",
"/**/*.js",
"/**/*.json",
"/**/*.bmp",
"/**/*.jpeg",
"/**/*.jpg",
"/**/*.png",
"/**/*.ttf",
"/**/*.eot",
"/**/*.svg",
"/**/*.woff",
"/**/*.woff2"
)
.addResourceLocations(staticLocations)
.setCachePeriod(cachePeriod);
registry.addResourceHandler("/**")
.addResourceLocations(indexLocations)
.setCachePeriod(cachePeriod)
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath,
Resource location) throws IOException {
return location.exists() && location.isReadable() ? location
: null;
}
});
}
}
@tmburnell
Copy link

I added .xlsx to the list because we had excel files we wanted to be able to download.

also I assumed several imports, since you did not provide them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment