项目启动时报错,一般都是由于配置问题,常见情况有以下几种,请参考解决。
ES 配置问题
启动时报错:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weCallBackController': Unsatisfied dependency expressed through field 'weEventHandle'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weEventHandle': Unsatisfied dependency expressed through field 'weCallBackEventFactoryMap'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weEventChangeContactImpl': Unsatisfied dependency expressed through field 'weStrategyBeanFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weStrategyBeanFactory' defined in file [D:\pactera\link-wechat\linkwe-wecom\target\classes\com\linkwechat\wecom\factory\WeStrategyBeanFactory.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'msg_audit_approved': Unsatisfied dependency expressed through field 'weChatContactMappingService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weChatContactMappingServiceImpl': Unsatisfied dependency expressed through field 'weConversationArchiveService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weConversationArchiveServiceImpl': Unsatisfied dependency expressed through field 'elasticSearch'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticSearch': Unsatisfied dependency expressed through field 'restHighLevelClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/linkwechat/common/config/ElasticSearchConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'restHighLevelClient' threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1
这种是由于项目中运用到了 ES,那项目运行必须需要 ES 吗?非必需。
**
如果不需要使用,只需要注释掉相关 ES 配置信息即可:
1、注释掉 pom.xml 中关于 ES 的配置;
2、注释掉 ElasticSearchConfig.java 类,这个配置读取了配置文件中的 ES 配置信息。
如果可以使用,需要在 application.yml 文件中,增加端口号:
# elasticsearch 配置
elasticsearch:
schema: http
# 这里记得增加端口号
address: 127.0.0.1:端口号
userName: ""
password: ""
connectTimeout: 10000
socketTimeout: 10000
connectionRequestTimeout: 10000
maxConnectNum: 100
maxConnectPerRoute: 100
Win 环境加载 Dll 文件问题
启动时报错:
java.lang.reflect.InvocationTargetException: null
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 com.linkwechat.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:56)
at com.linkwechat.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:33)
at com.linkwechat.quartz.util.QuartzDisallowConcurrentExecution.doExecute(QuartzDisallowConcurrentExecution.java:19)
at com.linkwechat.quartz.util.AbstractQuartzJob.execute(AbstractQuartzJob.java:44)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.UnsatisfiedLinkError: no WeWorkFinanceSdk in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.tencent.wework.Finance.(Finance.java:124)
at com.tencent.wework.FinanceUtils.initSDK(FinanceUtils.java:53)
at com.linkwechat.quartz.task.RyTask.FinanceTask(RyTask.java:88)
... 10 common frames omitted
这是由于在 Windows 环境下加载系统 Dll 文件的问题,可以尝试使用 System.load 方法加载 dll 文件:
static {
if (isWindows()) {
String path = System.getProperties().getProperty("user.dir");
System.load(path + File.separator + "libcrypto-1_1-x64.dll");
System.load(path + File.separator + "libcurl-x64.dll");
System.load(path + File.separator + "libssl-1_1-x64.dll");
System.load(path + File.separator + "WeWorkFinanceSdk.dll");
} else {
System.load("/data/jenkins_home/app/projects/libWeWorkFinanceSdk_Java.so");
}
}