|  |  |  | 
|---|
|  |  |  | package com.moral.api.config.Interceptor; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.boot.context.properties.ConfigurationProperties; | 
|---|
|  |  |  | import org.springframework.boot.system.ApplicationHome; | 
|---|
|  |  |  | import org.springframework.context.annotation.Bean; | 
|---|
|  |  |  | import org.springframework.context.annotation.Configuration; | 
|---|
|  |  |  | import org.springframework.web.servlet.config.annotation.InterceptorRegistration; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addResourceHandlers(ResourceHandlerRegistry registry) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); | 
|---|
|  |  |  | ApplicationHome h = new ApplicationHome(getClass()); | 
|---|
|  |  |  | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 | 
|---|
|  |  |  | String path = h.getSource().getParentFile().toString() + "/static/"; | 
|---|
|  |  |  | registry.addResourceHandler("/static/**").addResourceLocations("file:" + path); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|