Loading static resources with Spring Boot and Thymeleaf
Asked Answered
S

2

7

I want to get my static resources loaded. First I thought it already works, but that was just a trick of browser cache. I only get the html-files loaded as expected, but I dont get js, css, images and so on.

======

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 Project Resoureces

enter image description here

=====

Access to resoureces

Different styles of trying to get resource, no of them works!!!

enter image description here

Stpierre answered 9/1, 2015 at 21:10 Comment(0)
S
6

Okay, that helped me:

In WebMvcConfig I changed WebMvcConfigurationSupport to WebMvcAutoConfigurationAdapter

enter image description here

If you want to know about more about that module, better overview you find Stackoverflow-Link

Stpierre answered 9/1, 2015 at 22:20 Comment(0)
J
7

You don't need static in the path. Try /css/bbs-login.css.

Jarry answered 9/1, 2015 at 22:19 Comment(1)
Thanks for your answer, it helped changing WebMvcConfigurationSupport to WebMvcAutoConfigurationAdapter, then resources have been found. But I don't know why ...Stpierre
S
6

Okay, that helped me:

In WebMvcConfig I changed WebMvcConfigurationSupport to WebMvcAutoConfigurationAdapter

enter image description here

If you want to know about more about that module, better overview you find Stackoverflow-Link

Stpierre answered 9/1, 2015 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.