Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job-exception-handler解析问题 #170

Closed
elim168 opened this issue Nov 16, 2016 · 1 comment
Closed

job-exception-handler解析问题 #170

elim168 opened this issue Nov 16, 2016 · 1 comment

Comments

@elim168
Copy link

elim168 commented Nov 16, 2016

你好,我通过查看源码发现基于Spring的配置使用自定义JobExceptionHandler是不生效的。
通过查看源码发现在AbstractJobConfigurationDto.buildJobCoreConfiguration()构建JobCoreConfiguration对象时JobCoreConfiguration.Builder.jobProperties()方法的逻辑有点问题,其底层对应的JobProperties对象的逻辑如下:

    public void put(final String key, final String value) {
        JobPropertiesEnum jobPropertiesEnum = JobPropertiesEnum.from(key);
        if (null == jobPropertiesEnum || null == value) {
            return;
        }
        map.put(jobPropertiesEnum, value);
    }

在AbstractJobConfigurationDto.buildJobCoreConfiguration()进行调用的时候这个key传递的是对应枚举类型的名称,大写形式,然后JobPropertiesEnum.from(key)去取的时候是拿这个key跟其内部保存的key(小写形式)做比较来获取对应的JobPropertiesEnum对象的。大写对小写对不上,就导致不能获取到JobPropertiesEnum对象,然后就return了,也就是没有真正的丢进去。后续在用的时候就只能用默认的那个JobExceptionHandler了。我试了2.0.0和2.0.1都是这个问题。下面是JobPropertiesEnum的代码。

  public static enum JobPropertiesEnum
  {
    JOB_EXCEPTION_HANDLER("job_exception_handler", JobExceptionHandler.class, DefaultJobExceptionHandler.class.getCanonicalName()), 
    
    EXECUTOR_SERVICE_HANDLER("executor_service_handler", ExecutorServiceHandler.class, DefaultExecutorServiceHandler.class.getCanonicalName());
    
    private final String key;
    private final Class<?> classType;
    private final String defaultValue;
    
    private JobPropertiesEnum(String key, Class<?> classType, String defaultValue)
    {
      this.key = key;this.classType = classType;this.defaultValue = defaultValue;
    }
    
    public String getKey() { return this.key; }
    
    public Class<?> getClassType() { return this.classType; }
    
    public String getDefaultValue() { return this.defaultValue; }
    
    public static JobPropertiesEnum from(String key)
    {
      for (JobPropertiesEnum each : ) {
        if (each.getKey().equals(key)) {
          return each;
        }
      }
      return null;
    }
  }
@terrymanu
Copy link
Member

duplicate with #152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants