zoukankan      html  css  js  c++  java
  • 虚拟路径引起的bug

    之前,遇到一个问题,就是,项目访问不了最新产生的pdf文件。

    百思不得其解,为什么,返回 idea 页面就可以访问了(真的只是返回 idea 页面,不进行其他什么的操作)。一直以为是热部署的问题

    后来,在跟技术总管的交流下发现,其实是路径的问题,pdf 确实生成了,但是它只是保存在工程目录中,没有进入项目目录里。所以再次点击 idea 后,相当于,将其放入了项目目录里。

    额,总的而言,是访问的虚拟路径出了问题。

    贴一下解决代码。

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.*;
    
    
    @Configuration
    public class WebMvcConfig implements WebMvcConfigurer {
    
    
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.setUseSuffixPatternMatch(false);
        }
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler( "/pdfpdf/***" )
                    .addResourceLocations( "file:D:\" );
        }
    
    }
    

      这样之后,我可以通过,localhost:8080/pdfpdf/aaa.pdf,访问到,位于D盘下的 aaa.pdf 文件(文件真实存在的话)

    这个不起眼的小错误,卡了我3天。只能说,编程之路,任重道远!!!

  • 相关阅读:
    PAT 甲级 1115 Counting Nodes in a BST (30 分)
    PAT 甲级 1114 Family Property (25 分)
    PAT 甲级 1114 Family Property (25 分)
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
  • 原文地址:https://www.cnblogs.com/Kevin-QAQ/p/12364073.html
Copyright © 2011-2022 走看看