springboot 上传图片需要重新运行才能显示的问题
关于图片上传后需要重启服务器才能刷新图片,这是一种保护机制,为了防止绝对路径被看出来,目录结构暴露。
解决方法:将虚拟路径/images/向绝对路径(D:\\wb\\aaaa单\\基于springbootxx网站\\xxxproject\\src\\main\\resources\\static\\upload\\)映射。
@Configuration
public class webConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
System.out.println("配置文件已经生效");
String path="D:\\wb\\aaaa单\\基于springboot的xx网站\\xxxproject\\src\\main\\resources\\static\\upload\\";
registry.addResourceHandler("/static/upload/**").addResourceLocations("file:"+path);
.....
}
复制
request.getservletcontext报错
分析:servlet-api是servlet 3.0 版本之前的地址,javax.servlet-api 是servlet 3.0 版本之后的地址。上面的servlet-api资源中的HttpServletRequest对象中并没有getServletContext()方法解决:将servlet-api依赖换成javax-servlet-api。
解决:需要javax.servlet-api-3.x。x.jar的jar包(非mvn下载后放lib,mvn添加依赖)。
Eclipse中配置Ehcache(提示报错)
1.首先将 ehcache.xml 的 <ehcache>元素xsi:noNamespaceSchemaLocation 属性进行修改,本例为 xsi:noNamespaceSchemaLocation=" http://ehcache.xsd "。
2.打开eclipse,依次点击 Window -> Preferences -> XML -> XML Catalog-> User Specified Entries ,点击 Add 按钮,选择 Catalog Entry ,在 Location 输入 ehcache.xsd 路径,key type 选择 Schema location ,key 值填写步骤1中设置的xsi:noNamespaceSchemaLocation属性值http://ehcache.xsd ,点击ok就配置好了,现在可以提示了。
注:ehcache.xsd需要下载,下载后放到lib目录。