1.第一种失败的情况:

   本来使用Spring的上下文容器获取文件,将证书文件放在resource下,编译后获取文件会出现报错

java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : DerInputStream.getLength(): lengthTag=111, too big.
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:372)
at com.msok.signatured.crypto.KryptoUtil.getStoredPrivateKey(KryptoUtil.java:136)
at com.msok.signatured.xml.digsig.XmlDigitalSignatureGenerator.generateXMLDigitalSignatureXML(XmlDigitalSignatureGenerator.java:254)
at com.msok.signatured.xml.digsig.GetXmlDigtalSign.DigtalSignProcess(GetXmlDigtalSign.java:32)
at com.msok.insure.service.impl.PayJLYHServiceImpl.checkFour(PayJLYHServiceImpl.java:104)
at com.msok.insure.service.dubbo.PayPlatformFacadeImpl.payPlatForm(PayPlatformFacadeImpl.java:117)
at com.alibaba.dubbo.common.bytecode.Wrapper27.invokeMethod(Wrapper27.java)
at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)  

这个报错的原因是因为, maven会替换war中的证书文件替。那证书为什么会被修改呢,是maven-resources-plugin作怪。

详细资料有博客https://blog.csdn.net/wolf_love666/article/details/51448596 根据博主的解决方式可以处理该异常

2.第二部失败的情况

项目打包使用的SpringBoot打包成jar在服务器上部署,发现一直获取不到证书文件。

获取证书文件方式是

File pfxfile = SpringContextUtils.getApplicationContext().getResource("classpath:key" + File.separatorChar + xinyanProperties.getPfxName()).getFile();

  最后查找相关资料,这种获取文件的方式不能获取jar里边的文件,jar里边文件只能通过流的方式获取。

最后使用

InputStream stream = getClass().getClassLoader().getResourceAsStream("key" + File.separatorChar + xinyanProperties.getPfxName());

问题解决

SpringBoot获取resource下证书失败的更多相关文章

  1. springboot打成jar后获取classpath下文件失败

    原文链接:https://blog.csdn.net/qq_18748427/article/details/78606432 springboot打成jar后获取classpath下文件失败 使用如 ...

  2. 微信退款SpringBoot读取resource下的证书

    微信支付退款接口,需要证书双向验证,测试的时候证书暂时放在resource下,上图 起初MyConfig中我是这样,在本机IDE中运行没有问题 但到Linux服务器的docker中运行就IO异常了,查 ...

  3. Springboot获取resource的路径

    1.获取resource目录下的template路径 String path = Thread.currentThread().getContextClassLoader().getResource( ...

  4. springboot 获取Resource目录下的文件

    如图,获取user.png: 代码实现: //文件路径,此处static前不能加/,否则解析不到try { //此处的static前不能加/!!! file = ResourceUtils.getFi ...

  5. springboot项目获取resource下的文件

    package com.expr.exceldemo; import org.springframework.core.io.ClassPathResource; public class Test ...

  6. SpringBoot读取Resource下文件的几种方式

    https://www.jianshu.com/p/7d7e5e4e8ae3 最近在项目中涉及到Excle的导入功能,通常是我们定义完模板供用户下载,用户按照模板填写完后上传:这里模板位置resour ...

  7. java中根据key获取resource下properties资源文件中对应的参数

    properties资源文件是放在resource目录下的: 新建工具类: package com.demo.utils; import java.io.InputStream; import jav ...

  8. SpringBoot读取Resource下文件的几种方式(十五)

    需求:提供接口下载resources目录下的模板文件,(或者读取resources下的文件)给后续批量导入数据提供模板文件. 方式一:ClassPathResource //获取模板文件:注意此处需要 ...

  9. 获取resource下文件

    Resource resource = new ClassPathResource(certPath);File file= resource.getFile();

随机推荐

  1. 10大H5前端框架(转)

    10大H5前端框架 作为一名做为在前端死缠烂打6年并且懒到不行的攻城士,这几年我还是阅过很多同门从知名到很知名的各种前端框架,本来想拿15-20个框架来分享一下,但在跟几个前辈讨教写文章的技巧时果断被 ...

  2. 限制IP远程访问

    方法一:通过hosts.allow和hosts.deny文件进行ip限制 在/etc/目录下,同时存在hosts.allow和hosts.deny文件 如果我们希望某些ip不能访问,那么我们可以打开h ...

  3. as3.0 在数组中找个找个,并且替换

    var arr:Array=[1,2,7,9,3,5,6]; var findNum:Number =5//想要找到的数字 var replaceNum:Object =3//想要替换的数字 var ...

  4. Centos7 下的NTP-server(Chorny) 部署及客户端时间同步配置

    一.介绍 1.本博客以 ceph 集群搭建时的NTP-server 为例. 2.hosts # vim /etc/hosts 10.6.32.20    ceph1     (作为时间服务器) 10. ...

  5. 二分 poj 3273

    题目链接:https://vjudge.net/problem/POJ-3273 把n个连续的数字划分成m个连续的部分,每个部分都有一个部分和(这个部分所有值加起来),现在要使划分里最大的那个部分和最 ...

  6. NoHtml

    private string NoHtml(string Htmlstring) { if (string.IsNullOrWhiteSpace(Htmlstring)) return string. ...

  7. 使用css方法使footer保持在页面的最底部

    使footer保持在页面的底部,是常见的需求,之前面试的时候也遇见了一个这样的问题,今天在这里记录下css实现的方式. 使footer保持在页面的底部,需要考虑header+content部分不够多的 ...

  8. [剑指Offer]27-二叉树的镜像

    题目链接 https://www.nowcoder.com/practice/564f4c26aa584921bc75623e48ca3011?tpId=13&tqId=11171&t ...

  9. 在linux 中启动anaconda

    anaconda-navigator   $ source ~/anaconda3/bin/activate root ###在bin  目录下打开终端 敲 ./activate root   $ a ...

  10. python中if not x: 和 if x is not None: 和 if not x is None的使用和区别

    代码中经常会有变量是否为None的判断,有三种主要的写法: 第一种是`if x is None`: 第二种是 `if not x:`: 第三种是`if not x is None`(这句这样理解更清晰 ...