Skip to content

Can't springboot use the listener? #1918

Open
@xdxTao

Description

@xdxTao

I don't see how the springBootStarter uses the listener in the document. Can it not be used?

If I can, what's wrong with my writing?

MyListener

import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
import org.springframework.stereotype.Component;

@Component("simpleJobListener")
public class MyJobListener implements ElasticJobListener {
    @Override
    public void beforeJobExecuted(ShardingContexts shardingContexts) {
        System.out.println("before:" + shardingContexts.getJobName());
    }

    @Override
    public void afterJobExecuted(ShardingContexts shardingContexts) {
        System.out.println("after:" + shardingContexts.getJobName());
    }

    @Override
    public String getType() {
        return "simpleJobListener";
    }
}

MyYml

elasticjob:
  regCenter:
    #zookeeper 的ip:port
    serverLists: 127.0.0.1:2181
    #名命空间,自己定义就好了
    namespace: my-job13
  jobs:
    #你的这个定时任务名称,自定义名称
    oneSimpleJob:
      #定时任务的全路径名
      elasticJobClass: com.xdx97.elasticjob.job.OneSimpleJob
      #定时任务执行的cron表达式
      cron: 0/30 * * * * ?
      #分片数量
      shardingTotalCount: 1
      overwrite: true
      jobErrorHandlerType: EMAIL
      job-listener-types: simpleJobListener

In addition, please take another look #1917

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions