关于Not allowed to load local resource问题解决方案

关于Not allowed to load local resource问题解决方案

当页面上直接访问项目外的资源时会出现这个问题,它不允许我们直接访问系统中的资源,找了一些资料后配置了一个虚路径解决这个问题。

package com.example.wxhy.controller;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @Authof: Huangchenyang
 * @Date: Create in 16:32 2018/8/8
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/imagem/**").addResourceLocations("file:D:/code/barcode/");
        registry.addResourceHandler("/image/**").addResourceLocations("file:D:/image/");
    }
}

文件保存在实目录file:D:/code/barcode/下,访问的时候使用虚路径/image,比如文件名为1.png,就直接/image/1.png就ok了。

当然也可以写成配置文件的形式,但是还是要在类里面读取,索性直接写成配置类了

容器为tomcat的时候打开tomcat服务界面 在下面选择Modules 然后选择Add Web Module选择Browse 选择你的资源目录,然后填写path也是应该可以的,但是我没有测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值