SpringBoot获取resource下证书失败
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下证书失败的更多相关文章
- springboot打成jar后获取classpath下文件失败
原文链接:https://blog.csdn.net/qq_18748427/article/details/78606432 springboot打成jar后获取classpath下文件失败 使用如 ...
- 微信退款SpringBoot读取resource下的证书
微信支付退款接口,需要证书双向验证,测试的时候证书暂时放在resource下,上图 起初MyConfig中我是这样,在本机IDE中运行没有问题 但到Linux服务器的docker中运行就IO异常了,查 ...
- Springboot获取resource的路径
1.获取resource目录下的template路径 String path = Thread.currentThread().getContextClassLoader().getResource( ...
- springboot 获取Resource目录下的文件
如图,获取user.png: 代码实现: //文件路径,此处static前不能加/,否则解析不到try { //此处的static前不能加/!!! file = ResourceUtils.getFi ...
- springboot项目获取resource下的文件
package com.expr.exceldemo; import org.springframework.core.io.ClassPathResource; public class Test ...
- SpringBoot读取Resource下文件的几种方式
https://www.jianshu.com/p/7d7e5e4e8ae3 最近在项目中涉及到Excle的导入功能,通常是我们定义完模板供用户下载,用户按照模板填写完后上传:这里模板位置resour ...
- java中根据key获取resource下properties资源文件中对应的参数
properties资源文件是放在resource目录下的: 新建工具类: package com.demo.utils; import java.io.InputStream; import jav ...
- SpringBoot读取Resource下文件的几种方式(十五)
需求:提供接口下载resources目录下的模板文件,(或者读取resources下的文件)给后续批量导入数据提供模板文件. 方式一:ClassPathResource //获取模板文件:注意此处需要 ...
- 获取resource下文件
Resource resource = new ClassPathResource(certPath);File file= resource.getFile();
随机推荐
- php 读取网站页面源码的经典函数
Snoopy.class.php下载 include "inc/Snoopy.class.php"; //读取网页,返回网页源文件内容 function read_url($str ...
- FPGA基础知识1
1.乘法 在FPGA中,乘法运算可以分为 1)信号与信号之间的运算,用乘法器核实现: 2)常数与信号之间的运算,利用移位及加减法实现. A x 16 = A左移4位: A x 20 = A x 16 ...
- e-olymp Problem4196 Chocolate bars
吐槽一下,这个OJ的题目真的是阅读理解题.代码非常短,就是题目难理解.心累. 传送门:点我 Chocolate bars It is hard to overestimate the role of ...
- 100. Same Tree (Tree;DFS)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- NET Runtime version 2.0.50727.42 - 执行引擎错误 或者无法创建应用程序域
server2003操作系统 IIS运行应用程序报错,应用程序事件查看器详细: NET Runtime version 2.0.50727.42 - 执行引擎错误 或者无法创建应用程序域 解决方法:卸 ...
- swift - 高斯模糊
/* case extraLight case light case dark @available(iOS 10.0, *) case regular @available(iOS 10.0, ...
- ios 错误纪录
.self.出不来的原因 Member reference type 'struct objc_class *' is a pointer; maybe you meant to use '-> ...
- mysql 事务中如果有sql语句出错,会导致自动回滚吗?
事务,我们都知道具有原子性,操作要么全部成功,要么全部失败.但是有可能会造成误解. 我们先准备一张表,来进行测试 CREATE TABLE `name` ( `id` int(11) unsigned ...
- vs2017连接mysql以及问题汇总
https://www.cnblogs.com/eye-like/p/8494355.html https://blog.csdn.net/u012658972/article/details/791 ...
- odroid xu4
1, sd 2, flashing image 3, GParted 4, ROS install 5, make an image sudo dd if=/dev/sdb of=~/odroid/o ...