Created
April 24, 2017 15:26
-
-
Save mdeterman/e67839a7b673148dd5d49876ce8381cb to your computer and use it in GitHub Desktop.
Spring Config for SAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.