spring boot访问静态资源
2017-09-28 10:46
441 查看
遇到一个访问静态资源的坑,无法直接按照路径访问templates下面的资源,经过查询,需要实现WebMvcConfigurerAdapter。
package com.zkn.learnspringboot.config; import org.springframework.context.annotation.Configuration; import org.springframework.util.ResourceUtils; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * Created by wb-zhangkenan on 2016/11/30. */ @EnableWebMvc @Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/templates/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/templates/"); registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/"); super.addResourceHandlers(registry); } }
相关文章推荐
- springboot springMVC默认访问的静态资源
- springboot项目访问静态资源(默认方式)
- SpringBoot系列<四>视图解析、路径-资源映射、静态资源访问
- 关于springboot中的web项目不能访问templates中的静态资源
- Spring Boot无法访问css,js等静态资源的问题
- SpringBoot文件上传与静态资源访问
- spring boot整合Jersey时无法访问静态资源路径解决办法
- Spring-boot静态资源访问
- 为什么spring boot工程访问不到 静态资源
- SpringBoot设置静态资源访问目录
- 在SpringBoot中访问静态资源
- springboot 1.5.2 thymeleaf 添加templates 静态资源访问路径
- springboot jsp 静态资源访问
- 在SpringBoot中静态资源访问方法
- Springboot应用静态资源不能访问,报“This application has no explicit mapping for /error”
- 2-Spring Boot ( 静态资源访问 )
- spring boot 加入 spring-security配置 角色前缀 静态资源访问
- Spring Boot 设置静态资源访问
- springBoot配置静态访问资源
- spring boot 映射访问项目之外的静态资源