/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheWebConfig.java
41 строка
2 KB
sampadawagde
JAVA-3525: Moved spring-mvc-java-2 inside spring-web-modules
29 дек 2020, 21:14
29 дек 2020, 21:14
81b21f3
Код
Авторство
О чём код?
package com.baeldung.cache; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.http.CacheControl; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.mvc.WebContentInterceptor; import java.util.concurrent.TimeUnit; @EnableWebMvc @Configuration @ComponentScan(basePackages = {"com.baeldung.cache"}) public class CacheWebConfig implements WebMvcConfigurer { @Override public void addViewControllers(final ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); } @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/") .setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS) .noTransform() .mustRevalidate()); } @Override public void addInterceptors(InterceptorRegistry registry) { WebContentInterceptor interceptor = new WebContentInterceptor(); interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS) .noTransform() .mustRevalidate(), "/login/*"); registry.addInterceptor(interceptor); } }