wechatpay-java 部署linux报错

发布时间:2024年01月14日

ruoyimall部署linux环境报错

报错现象

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wechatPayService': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsapiService' defined in class path resource [com/cyl/config/WechatConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wechat.pay.java.service.payments.jsapi.JsapiService]: Factory method 'jsapiService' threw exception; nested exception is java.lang.IllegalArgumentException: java.security.InvalidKeyException: Illegal key size
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.ruoyi.RuoYiApplication.main(RuoYiApplication.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsapiService' defined in class path resource [com/cyl/config/WechatConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wechat.pay.java.service.payments.jsapi.JsapiService]: Factory method 'jsapiService' threw exception; nested exception is java.lang.IllegalArgumentException: java.security.InvalidKeyException: Illegal key size
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
... 27 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.wechat.pay.java.service.payments.jsapi.JsapiService]: Factory method 'jsapiService' threw exception; nested exception is java.lang.IllegalArgumentException: java.security.InvalidKeyException: Illegal key size
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:652)
... 40 common frames omitted
Caused by: java.lang.IllegalArgumentException: java.security.InvalidKeyException: Illegal key size
at com.wechat.pay.java.core.cipher.AbstractAeadCipher.decrypt(AbstractAeadCipher.java:83)
at com.wechat.pay.java.core.certificate.AbstractAutoCertificateProvider.decryptCertificate(AbstractAutoCertificateProvider.java:157)
at com.wechat.pay.java.core.certificate.AbstractAutoCertificateProvider.downloadAndUpdate(AbstractAutoCertificateProvider.java:122)
at com.wechat.pay.java.core.certificate.AbstractAutoCertificateProvider.<init>(AbstractAutoCertificateProvider.java:89)
at com.wechat.pay.java.core.certificate.AbstractAutoCertificateProvider.<init>(AbstractAutoCertificateProvider.java:49)
at com.wechat.pay.java.core.certificate.RSAAutoCertificateProvider.<init>(RSAAutoCertificateProvider.java:32)
at com.wechat.pay.java.core.certificate.RSAAutoCertificateProvider.<init>(RSAAutoCertificateProvider.java:21)
at com.wechat.pay.java.core.certificate.RSAAutoCertificateProvider$Builder.build(RSAAutoCertificateProvider.java:111)
at com.wechat.pay.java.core.RSAAutoCertificateConfig$Builder.build(RSAAutoCertificateConfig.java:114)
at com.cyl.wechat.WechatPayConfig.getInstance(WechatPayConfig.java:23)
at com.cyl.config.WechatConfig.jsapiService(WechatConfig.java:17)
at com.cyl.config.WechatConfig$$EnhancerBySpringCGLIB$$3d407f19.CGLIB$jsapiService$0(<generated>)
at com.cyl.config.WechatConfig$$EnhancerBySpringCGLIB$$3d407f19$$FastClassBySpringCGLIB$$a7d6bd2e.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.cyl.config.WechatConfig$$EnhancerBySpringCGLIB$$3d407f19.jsapiService(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 41 common frames omitted
Caused by: java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
at javax.crypto.Cipher.implInit(Cipher.java:805)
at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
at javax.crypto.Cipher.init(Cipher.java:1396)
at javax.crypto.Cipher.init(Cipher.java:1327)
at com.wechat.pay.java.core.cipher.AbstractAeadCipher.decrypt(AbstractAeadCipher.java:71)
... 61 common frames omitte

解决方案

首先进入%JAVE_HOME%/jre/lib/security/ 目录,看下目录里面是有一个 policy 文件夹,还是有local_policy.jar,US_export_policy.jar两个jar包,如下两种情况
在这里插入图片描述
第一种情况:如果有policy 文件夹,说明此版本为JVM启用 无限制强度管辖策略 有了一种新的更简单的方法。
请在 当前文件夹中查找文件 java.security。
现在用文本编辑器打开java.security,并找到定义java安全性属性crypto.policy的行,它可以有两个值limited或unlimited - 默认值是limited。
默认情况下,您应该能找到一条注释掉的行:

#crypto.policy=unlimited
  • 1

您可以通过取消注释该行来启用无限制,删除#:

crypto.policy=unlimited
  • 1

现在重新启动指向JVM的Java应用程序即可。

第二种情况:没有policy 文件夹,而是直接就有local_policy.jar,US_export_policy.jar两个jar包。

去官方下载JCE无限制权限策略文件。
jdk 5: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html#jce_policy-1.5.0-oth-JPR
jdk6: http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
JDK7的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
JDK8的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt
将两个jar文件放到%JAVE_HOME%\jre\lib\security目录下覆盖原来文件。

文章来源:https://blog.csdn.net/qq_41737694/article/details/135572083
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。