【开发环境】配置文件加载失败,启动报错** must not be empty

环境:
MacBook Pro 13
jdk8
IntelliJ IDEA 2018.3.3

1. 问题描述

项目依赖Apollo配置,本地可以配置config-cache 加载配置。
最近项目config 突然加载异常, 显示某个属性must not be empty
部分异常信息。

2. 问题分析

  1. 最近发现
  2. 项目刚起动就跑异常

针对12 两点分析。
验证1, 加载unitTest 尝试是否能加载本地config-cache
结果发现,加载失败,并从报错信息找到root cause



2020-02-25 18:41:44,216 ERROR Application startup resulted in exception
com.google.inject.CreationException: Unable to create injector, see the following errors:

1) Error in custom provider, java.lang.IllegalArgumentException: resourceName must not be empty
  while locating com.leyantech.inspector.conf.db.DruidDataSourceProvider
  at org.mybatis.guice.MyBatisModule.bindDataSourceProviderType(MyBatisModule.java:289) (via modules: com.leyantech.inspector.conf.di.InspectorGuiceModule -> com.google.inject.util.Modules$OverrideModule -> com.leyantech.inspector.conf.di.DefaultMybatisModule)
  while locating javax.sql.DataSource
    for field at org.mybatis.guice.environment.EnvironmentProvider.dataSource(EnvironmentProvider.java:52)
  at org.mybatis.guice.environment.EnvironmentProvider.class(EnvironmentProvider.java:27)
  while locating org.mybatis.guice.environment.EnvironmentProvider
  at org.mybatis.guice.MyBatisModule.internalConfigure(MyBatisModule.java:110) (via modules: com.leyantech.inspector.conf.di.InspectorGuiceModule -> com.google.inject.util.Modules$OverrideModule -> com.leyantech.inspector.conf.di.DefaultMybatisModule$1)
  while locating org.apache.ibatis.mapping.Environment
    for the 1st parameter of org.mybatis.guice.configuration.ConfigurationProvider.(ConfigurationProvider.java:109)
  at org.mybatis.guice.configuration.ConfigurationProvider.class(ConfigurationProvider.java:39)
  while locating org.mybatis.guice.configuration.ConfigurationProvider
  at org.mybatis.guice.MyBatisModule.internalConfigure(MyBatisModule.java:113) (via modules: com.leyantech.inspector.conf.di.InspectorGuiceModule -> com.google.inject.util.Modules$OverrideModule -> com.leyantech.inspector.conf.di.DefaultMybatisModule$1)
  while locating org.apache.ibatis.session.Configuration
    for the 1st parameter of org.mybatis.guice.session.SqlSessionFactoryProvider.createNewSqlSessionFactory(SqlSessionFactoryProvider.java:59)
  at org.mybatis.guice.session.SqlSessionFactoryProvider.class(SqlSessionFactoryProvider.java:26)
  while locating org.mybatis.guice.session.SqlSessionFactoryProvider
  while locating org.apache.ibatis.session.SqlSessionFactory
    for the 1st parameter of org.mybatis.guice.session.SqlSessionManagerProvider.createNewSqlSessionManager(SqlSessionManagerProvider.java:49)
  at org.mybatis.guice.session.SqlSessionManagerProvider.class(SqlSessionManagerProvider.java:24)
  while locating org.mybatis.guice.session.SqlSessionManagerProvider
  at org.mybatis.guice.AbstractMyBatisModule.configure(AbstractMyBatisModule.java:59) (via modules: com.leyantech.inspector.conf.di.InspectorGuiceModule -> com.google.inject.util.Modules$OverrideModule -> com.leyantech.inspector.conf.di.DefaultMybatisModule$1)
  while locating org.apache.ibatis.session.SqlSessionManager
    for field at org.mybatis.guice.mappers.MapperProvider.sqlSessionManager(MapperProvider.java:37)
  while locating org.mybatis.guice.mappers.MapperProvider
  at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
  at org.mybatis.guice.AbstractMyBatisModule.bindMapper(AbstractMyBatisModule.java:96) (via modules: com.leyantech.inspector.conf.di.InspectorGuiceModule -> com.google.inject.util.Modules$OverrideModule -> com.leyantech.inspector.conf.di.DefaultMybatisModule)
Caused by: java.lang.IllegalArgumentException: resourceName must not be empty
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:141)

1 打开vivo 项目增加 测试code

public class LocalApolloTest {

  static {
    System.setProperty("app.id", "430");
  }

  public static void main(String[] args) {
    Config config = ConfigService.getAppConfig();
    System.out.println(
        config.getProperty("inspector.jdbc.driverName", "failed")); // default value is "failed"
  }
}

output:

2020-02-25 20:39:41,707 WARN Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.LocalFileConfigRepository, reason: Load config from local config failed! [Cause: Cannot read from local cache file /Users/**/workspace/gitlab/oppo/config-cache/430+default+application.properties]
2020-02-25 20:39:41,712 WARN Init Apollo Local Config failed - namespace: application, reason: Load config from local config failed! [Cause: Cannot read from local cache file /Users/**/workspace/gitlab/oppo/config-cache/430+default+application.properties].
2020-02-25 20:39:41,716 WARN Could not load config for namespace application from Apollo, please check whether the configs are released in Apollo! Return default value now!
`failed`

和 local config相去甚远.
【开发环境】配置文件加载失败,启动报错** must not be empty_第1张图片

同时console 中输出重要信息:

/Users/**/workspace/gitlab/oppo/config-cache/430+default+application.properties].

这里配置为啥会从 oppo 项目加载呢?

解决办法:
看一下IDEA 目录结构:
【开发环境】配置文件加载失败,启动报错** must not be empty_第2张图片

由于这个IDEA 第一个打开的是oppo 项目,导致其他以import module 进入的项目,加载config 时目录都变成 /**/oppo/**.properties.

即只需要重新open 需要项目的IDEA即可。

。。。

你可能感兴趣的:(工作日常,环境搭建,IntelliJ,IDEA)