Loading static resources with Spring Boot and Thymeleaf

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 15:31:35

问题


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

=====

Access to resoureces

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


回答1:


Okay, that helped me:

In WebMvcConfig I changed WebMvcConfigurationSupport to WebMvcAutoConfigurationAdapter

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




回答2:


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



来源:https://stackoverflow.com/questions/27869267/loading-static-resources-with-spring-boot-and-thymeleaf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!