项目启动时报错,一般都是由于配置问题,常见情况有以下几种,请参考解决。

ES 配置问题

启动时报错:

  1. 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 文件中,增加端口号:

  1. # elasticsearch 配置
  2. elasticsearch:
  3. schema: http
  4. # 这里记得增加端口号
  5. address: 127.0.0.1:端口号
  6. userName: ""
  7. password: ""
  8. connectTimeout: 10000
  9. socketTimeout: 10000
  10. connectionRequestTimeout: 10000
  11. maxConnectNum: 100
  12. maxConnectPerRoute: 100


Win 环境加载 Dll 文件问题

启动时报错:

  1. java.lang.reflect.InvocationTargetException: null
  2. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  3. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  4. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  5. at java.lang.reflect.Method.invoke(Method.java:498)
  6. at com.linkwechat.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:56)
  7. at com.linkwechat.quartz.util.JobInvokeUtil.invokeMethod(JobInvokeUtil.java:33)
  8. at com.linkwechat.quartz.util.QuartzDisallowConcurrentExecution.doExecute(QuartzDisallowConcurrentExecution.java:19)
  9. at com.linkwechat.quartz.util.AbstractQuartzJob.execute(AbstractQuartzJob.java:44)
  10. at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
  11. at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
  12. Caused by: java.lang.UnsatisfiedLinkError: no WeWorkFinanceSdk in java.library.path
  13. at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
  14. at java.lang.Runtime.loadLibrary0(Runtime.java:870)
  15. at java.lang.System.loadLibrary(System.java:1122)
  16. at com.tencent.wework.Finance.(Finance.java:124)
  17. at com.tencent.wework.FinanceUtils.initSDK(FinanceUtils.java:53)
  18. at com.linkwechat.quartz.task.RyTask.FinanceTask(RyTask.java:88)
  19. ... 10 common frames omitted

这是由于在 Windows 环境下加载系统 Dll 文件的问题,可以尝试使用 System.load 方法加载 dll 文件:

  1. static {
  2. if (isWindows()) {
  3. String path = System.getProperties().getProperty("user.dir");
  4. System.load(path + File.separator + "libcrypto-1_1-x64.dll");
  5. System.load(path + File.separator + "libcurl-x64.dll");
  6. System.load(path + File.separator + "libssl-1_1-x64.dll");
  7. System.load(path + File.separator + "WeWorkFinanceSdk.dll");
  8. } else {
  9. System.load("/data/jenkins_home/app/projects/libWeWorkFinanceSdk_Java.so");
  10. }
  11. }