SpringBoot 自定义Controller静态资源被拦截的的问题解决方案

原文链接:http://www.jianshu.com/p/9135db91d702
package com.qiuzq.jz.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class DefaultView extends WebMvcConfigurationSupport {


/**
  * 设置对主页的跳转
  * @param registry
 */
@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("index");
    registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    super.addViewControllers(registry);
}


/**
 * 解决跳转后静态资源无法访问的问题
 *
 * @param registry
 */
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
   }
}

// 最后需要在启动类上扫描该包
@SpringBootApplication
@ComponentScan({"com.qiuzq.jz.config"})
public class JzApplication {
public static void main(String[] args) {
    SpringApplication.run(JzApplication.class, args);
  }
}
展开阅读全文

没有更多推荐了,返回首页