美文网首页
设置虚拟路径下载服务器模板问题

设置虚拟路径下载服务器模板问题

作者: 墨色尘埃 | 来源:发表于2018-03-30 23:17 被阅读77次
image.png
微信图片_20180329183815.png

nginx代理,加了权限之后
点击下载模板功能,跳转到http://10.10.200.187/templates/企业信息管理.xls,10.10.200.187是nginx的代理,访问的是10.10.200.18的服务器,18服务器上的后台配置文件里定义的模板地址是:resourceLocations: file:/D:/FTP_FILES/QYY/templates/,而18服务器上的D:/FTP_FILES/QYY/templates/这个路径下并没有模板所以会导致访问的请求404,解决的方法①就是在18服务器的这个目录下放置模板就可以了。②另一个解决办法是:修改配置文件中的模板路径地址,改为指向真实存放模板的路径,这里是放在200.6服务器上,试试改为如下

resourceLocations: file:/ftp://10.10.200.6/D:/FTP_FILES/QYY/templates/
resourceLocations: ftp://10.10.200.6/D:/FTP_FILES/QYY/templates/

而之前用本机能测试成功是因为,点击下载模板按钮会跳转到http://172.16.11.66:10002/templates/企业信息管理.xls,正因为66服务器的D:/FTP_FILES/QYY/templates/路径下有模板所以可以下载成功

image.png

注:在文件夹中也可以访问ftp,比如输入ftp://172.16.11.66/,输入ftp用户名和密码即刻呈现如下

image.png

未使用代理,加了权限之后
加了权限之后,所有的请求或者url路径就要在同一个域名下访问
比如企业云:在localhost:8000下下载模板功能,如果点击之后跳转到http://172.16.11.66:10002/templates/企业信息管理.xls会报401错误,这是因为在不同的域名下(localhost和172.16.11.66)权限不通。所以想要下载到模板,跳转路径应该改为http://localhost:8000/templates/企业信息管理.xls,并在本地电脑的D:/FTP_FILES/QYY/templates/目录下建立对应的文件夹

templatePath: #抄表预警模板地址
  rootPath: excelTemplate/chaobiaoyujing.xlsx
  copyRootPath: D:/chaobiaoyujing1.xlsx
  resourceHeader: /templates/**
  resourceLocations: file:/D:/FTP_FILES/QYY/templates/
image.png

同理,如果是在http://127.0.0.1:8000/#/EnterpriseCloud/BasicDataManage下的下载模板功能,①先登陆后有权限,再跳转http://127.0.0.1:8000/templates/企业信息管理.xls才能下载(是否需要登录系统需看SecurityConfig类中是否设置了权限),②如果未登录点击http://127.0.0.1:8000/templates/企业信息管理.xls路径会提示401没有权限错误。③如果跳转到http://localhost:8000/templates/企业信息管理.xls则会报401错误,错误如下

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Apr 02 16:39:19 CST 2018
There was an unexpected error (type=Unauthorized, status=401).
Full authentication is required to access this resource

这里的http://127.0.0.1:8000/templates/企业信息管理.xls并不是一个接口,而是通过MyConfiguration设置成的一个url地址,参考文章springboot访问静态资源springboot访问本地路径获取图片url和通过接口获取图片并缓存springboot静态资源文件映射
SecurityConfig权限设置

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry
                expressionInterceptUrlRegistry = http.exceptionHandling().authenticationEntryPoint
                (securityException401EntryPoint())
                .and()
                .csrf()
                .disable()
                .headers()
                .frameOptions()
                .sameOrigin()
                .and()
                .logout().addLogoutHandler(new SecurityContextLogoutHandler())
                .and()
                .authorizeRequests()
                .antMatchers("/security/loginByPwd").permitAll()
                .antMatchers("/security/loginByToken").permitAll()
                .antMatchers("/security/vcode").permitAll()
                .antMatchers("/v1/userInfo/login").permitAll()
                .antMatchers("/v1/password/revise").permitAll()
                .antMatchers("/v1/password/user").permitAll()
                .antMatchers("/v1/dataList").permitAll()
//                .antMatchers("/templates/*.xls").permitAll() //允许所有权限
//                .antMatchers("/templates/*.xlsx").permitAll() //允许所有权限
                .antMatchers("/*.jpg").permitAll()
                .antMatchers(HttpMethod.POST, "/v1/repair").permitAll()
                .antMatchers(HttpMethod.POST, "/v1/complain").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/menus").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/articleInfo").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/shopInfo").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/rentPublic").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/rent/detail").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/goodsInfo").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/goodsIntroInfo").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/articleContentInfo").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/attachment/image").permitAll()
                .antMatchers(HttpMethod.GET, "/v1/evaluationInfo").permitAll();

        //正式环境下所有的请求都要经过验证
        if (envActive.equals("prod")) {
            expressionInterceptUrlRegistry.accessDecisionManager(accessDecisionManager()).anyRequest().authenticated();
        } else {
            expressionInterceptUrlRegistry.anyRequest().permitAll();
        }
//                .permitAll()  //权限允许所有人

//                .and()
//                .sessionManagement()
//                .invalidSessionUrl("/login")
//                .maximumSessions(5)


    }

MyConfiguration

@Configuration
public class MyConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    TemplateConfig templateConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * @Description: 对文件的路径进行配置, 创建一个虚拟路径/rules/** ,即只要在<img src="/rules/picName.jpg" />便可以直接引用图片
         *这是图片的物理路径  "file:/+本地图片的地址"
         */
//        registry.addResourceHandler("/rules/**").addResourceLocations
//                ("classpath:/rules/");
        registry.addResourceHandler(templateConfig.getResourceHeader()).addResourceLocations
                (templateConfig.getResourceLocations());

//        registry.addResourceHandler("/templates/**").addResourceLocations
//                ("file:\\E:\\IdeaProjects\\gaygserver\\src\\main\\resources\\static\\");
//        registry.addResourceHandler("/templates/**").addResourceLocations
//                ("classpath:/static/");

//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
//        registry.addResourceHandler("/**").addResourceLocations("file:\\E:\\IdeaProjects\\gaygserver\\src" +
//                "\\main\\resources\\static\\");
        super.addResourceHandlers(registry);
    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //和页面有关的静态目录都放在项目的static目录下
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
//        //上传的图片在D盘下的OTA目录下,访问路径如:http://localhost:8081/OTA/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
//        //其中OTA表示访问的前缀。"file:D:/OTA/"是文件真实的存储路径
//        registry.addResourceHandler("/OTA/**").addResourceLocations("file:D:/OTA/");
//    }
}

相关文章

  • 设置虚拟路径下载服务器模板问题

    nginx代理,加了权限之后点击下载模板功能,跳转到http://10.10.200.187/templates/...

  • Django笔记(三) 模板和目录等

    模板 模板路径 //模板路径设置(新版本使用默认??》一般使用默认,有需求时再去设置) 模板继承 {% exten...

  • DownLoadManager遇到的问题

    问题1 问题描述:使用DownLoadManager下载,设置好下载文件的存放路径。当我们根据这个路径去读取文件的...

  • 用户上传文件图片放在项目外

    tomcat中用户上传文件图片到非项目路径下、并设置虚拟路径访问 服务器配置文件修改、代码编写 eclipse中设...

  • Django教程(3)——用模板建站

    目标:设置静态文件的路径;了解模板的使用方法。 1. 设置静态文件的路径 模板的路径设置已在上一节的内容中说过。而...

  • git commit 模板设置

    1.设置模板路径,其中path就是commit模板路径git config --global commit.tem...

  • Django05

    模板和静态媒体 设置模版目录设置一个储存模板的目录:绝对路径还是相对路径? 选择相对路径更好BASE_DIR内容是...

  • 2019-02 Pyspark 初探

    0. 安装及环境   a. 下载JDK并设置环境路径 (官网下载pkg文件)  b. 下载Spark并设置环境路径...

  • PyCharm 中修改脚本默认模板

    Pycharm 可以设置默认模板,这样每次创建 Python file 后,都会按照预设的模板写入内容。设置路径为...

  • linux 下 Nginx 设置图片服务器

    下载安装 centos7下RPM方式安转nginx 设置图片服务器 查找安装路径ps aux | grep ngi...

网友评论

      本文标题:设置虚拟路径下载服务器模板问题

      本文链接:https://www.haomeiwen.com/subject/lqywcftx.html