diff options
author | Vitaly Takmazov | 2018-11-20 01:12:23 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-20 01:12:23 +0300 |
commit | 152efe1f31e1e568272fc401a3a19f2c6f7c9c49 (patch) | |
tree | b10aaf75cb93bd9bd8c73d705774e20e1ce7faa4 /src | |
parent | 930e6ab6d604963ae6a48c58fc1bd3735071d9ee (diff) |
Avatars versioning
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/server/configuration/BaseWebConfiguration.java | 3 | ||||
-rw-r--r-- | src/main/java/com/juick/server/configuration/WwwAppConfiguration.java | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java b/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java index 23a35384..6a2a8142 100644 --- a/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java +++ b/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java @@ -25,6 +25,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; +import javax.annotation.Nonnull; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -47,7 +48,7 @@ public class BaseWebConfiguration implements WebMvcConfigurer, SchedulingConfigu } @Override - public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + public void configureTasks(@Nonnull ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setScheduler(taskExecutor()); } diff --git a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java index 72889f96..534154af 100644 --- a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java +++ b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java @@ -31,15 +31,20 @@ import org.commonmark.ext.autolink.AutolinkExtension; import org.commonmark.node.Link; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.CacheControl; import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.resource.VersionResourceResolver; import javax.inject.Inject; import java.util.Collections; +import java.util.concurrent.TimeUnit; /** * Created by aalexeev on 11/22/16. @@ -51,6 +56,8 @@ public class WwwAppConfiguration implements WebMvcConfigurer { private UserService userService; @Inject private TagService tagService; + @Value("${avatars_path:#{systemEnvironment['TEMP'] ?: 'file:/tmp/'}}") + private String avatarsPath; @Bean public CaffeineCacheManager cacheManager() { return new CaffeineCacheManager("help"); @@ -117,4 +124,13 @@ public class WwwAppConfiguration implements WebMvcConfigurer { viewResolver.setCharacterEncoding(CharEncoding.UTF_8); return viewResolver; } + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry + .addResourceHandler("/**", "/i/a/**") + .addResourceLocations("classpath:/static/", avatarsPath) + .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)) + .resourceChain(false) + .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**", "/i/a/**")); + } } |