Loading static resources with Spring Boot and Thymeleaf
I want to load my static resources. At first I thought this was already working, but this is just a browser cache trick. I only load html files as expected, but I am not getting js, css, images, etc.
======
My StartClass:
@Configuration
@Import({ ServiceConfig.class, WebMvcConfig.class })
@EnableHypermediaSupport(type = HAL)
@EnableAutoConfiguration
public class ApplicationClientMvc {
public static void main(final String[] args) {
SpringApplication.run(ApplicationClientMvc.class, args);
}
}
======
WebMvcConfig
@Configuration
@ComponentScan
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Autowired public SpringTemplateEngine templateEngine;
@Bean
public ThymeleafTilesConfigurer tilesConfigurer() {
final ThymeleafTilesConfigurer configurer = new ThymeleafTilesConfigurer();
configurer.setDefinitions("classpath*:/templates/**/views.xml");
return configurer;
}
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
final ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setViewClass(ThymeleafTilesView.class);
resolver.setTemplateEngine(templateEngine);
resolver.setCharacterEncoding(UTF_8);
return resolver;
}
@Bean
public TilesDialect tilesDialect() {
return new TilesDialect();
}
//
@Value("${server.session-timeout}") private Long sessionTimeOut;
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(sessionTimeOut * 1000L);
configurer.registerCallableInterceptors(timeoutInterceptor());
}
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
}
}
======
My Resoureces Project
=====
Access to resources
Various styles try to get the resource, none of them work !!!
+3
source to share
2 answers
Ok this helped me:
In WebMvcConfig, I changed WebMvcConfigurationSupport
toWebMvcAutoConfigurationAdapter
If you want to know more about this module, you can find the best overview at fooobar.com/questions/2190664 / ...
+5
source to share