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();
随机推荐
- 【C++】预处理过程与语句总结
转载请保留: http://www.cnscn.org(CNS电脑与英语学习网) Author: cnscn http://www.cnscn.org 1)预处理 根据已放置在文件中的预处理指令来修改 ...
- Android设置ScrollView回到顶部的三种方式 (转)
一.ScrollView.scrollTo(0,0) 直接置顶,瞬间回到顶部,没有滚动过程,其中Y值可以设置为大于0的值,使Scrollview停在指定位置; 二.ScrollView.fullSc ...
- idea插件推荐
CodeGlance 类似SublimeText的Mini Map插件 Background Image Plus 这又是一款装备B插件了,想想别人看到你的IDE有个美女或者异次元背景是怎样的,安装 ...
- HTTP协议原理(长连接,短连接/ get,post区别等等)
HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...
- Evaluate Reverse Polish Notation (STRING-TYPE CONVERTION)
Question Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators a ...
- 【环境配置】本地配置sublime text以及和远程linux设置sftp
工具: sublime text 2(mac版) 远程linux(centos 7系) securCRT(for mac) [本地安装并配置securCRT(for mac)] 关于配置: 1.解决终 ...
- multithreading coding
分类:公共资源问题.公交车问题 顺序:Qseater lab, bank, doctor [饭店] geust //yuec2 Yue Cheng package lab9; public abstr ...
- 纯css实现div中未知尺寸图片的垂直居中
1.淘宝的方法 在曾经的"淘宝UED招聘"中有这样一道题目: “使用纯CSS实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中.” 当然出题并不是 ...
- 处理后台向前台传递的json数据
在pom文件中添加下面三种依赖jar包 <dependency> <groupId>com.fasterxml.jackson.core</groupId> < ...
- Failed to read artifact descriptor for xxx:jar的问题解决
在开发的过程中,尤其是新手,我们经常遇到Maven下载依赖jar包的问题,也就是遇到“Failed to read artifact descriptor for xxx:jar”的错误. 对于这种非 ...