问题详情:IEDA运行没问题,运行jar包报错,报错如下
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lcbpPayCMBC' defined in URL [jar:file:/data/project/lm-payment-proxy.jar!/BOOT-INF/classes!/com/langma/payment/pay/LcbpPayCMBC.class]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
java_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334)
java_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
java_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
java_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
java_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
java_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
java_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
java_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
java_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
java_1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:920)
java_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
java_1 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
java_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
java_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
java_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
java_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
java_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
java_1 | at com.langma.payment.PaymentManageApplication.main(PaymentManageApplication.java:11)
java_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
java_1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java_1 | at java.base/java.lang.reflect.Method.invoke(Method.java:566)
java_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
java_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
java_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
java_1 | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
java_1 | Caused by: java.lang.ExceptionInInitializerError: null
java_1 | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
java_1 | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
java_1 | at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java_1 | at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
java_1 | at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
java_1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
java_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
java_1 | ... 25 common frames omitted
java_1 | Caused by: java.lang.NullPointerException: null
java_1 | at java.base/java.util.Objects.requireNonNull(Objects.java:221)
java_1 | at java.base/java.util.ImmutableCollections$MapN.<init>(ImmutableCollections.java:827)
java_1 | at java.base/java.util.Map.of(Map.java:1327)
java_1 | at com.langma.payment.pay.LcbpPayCMBC.<clinit>(LcbpPayCMBC.java:60)
java_1 | ... 32 common frames omitted
问题突破点:
java_1 | Caused by: java.lang.NullPointerException: null
java_1 | at java.base/java.util.Objects.requireNonNull(Objects.java:221)
java_1 | at java.base/java.util.ImmutableCollections$MapN.<init>(ImmutableCollections.java:827)
java_1 | at java.base/java.util.Map.of(Map.java:1327)
java_1 | at com.langma.payment.pay.LcbpPayCMBC.<clinit>(LcbpPayCMBC.java:60)
java_1 | ... 32 common frames omitted
源代码:
@Service
@Slf4j
public class LcbpPayCMBC extends AbstractPaymentStrategy {
// 支付类型
private static final Map<String, String> selectTradeTypeMap = Map.of(
"XXXX", "XXXX",
"XXXX", "XXXX",
"XXXX", "XXXX"
);
// 支付主体
private static final Map<String, String> subAppId = Map.of(
"XXXX", CMBCConfig.gzhAppId,
"XXXX", CMBCConfig.xcxAppId
);
}
问题原因:
Spring在实例化这个类的时候,先执行静态方法,此时CMBCConfig这个类还未实例化(检查是否已加注解),故而报了这个空指针错误。
解决方法:
修改代码如下
#加上注解
@DependsOn("CMBCConfig")