You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/06/19 17:23:31 UTC
[shardingsphere-elasticjob-lite] branch master updated: Refactor
spring namespace, avoid use extend JobScheduler (#794)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new 7b2a648 Refactor spring namespace, avoid use extend JobScheduler (#794)
7b2a648 is described below
commit 7b2a648951cca268ceb774c76a5d629bf322ecf2
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jun 20 01:21:39 2020 +0800
Refactor spring namespace, avoid use extend JobScheduler (#794)
* Refactor spring namespace, avoid use extend JobScheduler
* remove useless SpringJobScheduler
* move package
* Add final for JobScheduler
---
.../elasticjob/lite/api/JobScheduler.java | 13 ++---
.../InstanceProvidedDataflowJobConfiguration.java | 43 ++++++++++++++
.../InstanceProvidedSimpleJobConfiguration.java | 41 ++++++++++++++
.../config/provided/JobInstanceProvided.java | 33 +++++++++++
.../AbstractJobConfigurationGsonTypeAdapter.java | 10 +++-
.../lite/spring/api/SpringJobScheduler.java | 66 ----------------------
.../common/AbstractJobBeanDefinitionParser.java | 14 +----
.../dataflow/DataflowJobBeanDefinitionParser.java | 9 ++-
.../simple/SimpleJobBeanDefinitionParser.java | 9 ++-
9 files changed, 145 insertions(+), 93 deletions(-)
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java
index 577cb13..bde57cd 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java
@@ -36,6 +36,7 @@ import org.apache.shardingsphere.elasticjob.lite.internal.schedule.LiteJob;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.LiteJobFacade;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.SchedulerFacade;
import org.apache.shardingsphere.elasticjob.lite.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.lite.internal.config.provided.JobInstanceProvided;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
@@ -45,13 +46,12 @@ import org.quartz.simpl.SimpleThreadPool;
import java.util.Arrays;
import java.util.List;
-import java.util.Optional;
import java.util.Properties;
/**
* Job scheduler.
*/
-public class JobScheduler {
+public final class JobScheduler {
private static final String ELASTIC_JOB_DATA_MAP_KEY = "elasticJob";
@@ -135,9 +135,8 @@ public class JobScheduler {
private JobDetail createJobDetail(final String jobClass) {
JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(liteJobConfig.getJobName()).build();
result.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade);
- Optional<ElasticJob> elasticJobInstance = createElasticJobInstance();
- if (elasticJobInstance.isPresent()) {
- result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJobInstance.get());
+ if (liteJobConfig.getTypeConfig() instanceof JobInstanceProvided && null != ((JobInstanceProvided) liteJobConfig.getTypeConfig()).getJobInstance()) {
+ result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, ((JobInstanceProvided) liteJobConfig.getTypeConfig()).getJobInstance());
} else if (!jobClass.equals(ScriptJob.class.getCanonicalName())) {
try {
result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, Class.forName(jobClass).newInstance());
@@ -148,10 +147,6 @@ public class JobScheduler {
return result;
}
- protected Optional<ElasticJob> createElasticJobInstance() {
- return Optional.empty();
- }
-
/**
* Shutdown job.
*/
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/InstanceProvidedDataflowJobConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/InstanceProvidedDataflowJobConfiguration.java
new file mode 100644
index 0000000..40c1dd6
--- /dev/null
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/InstanceProvidedDataflowJobConfiguration.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.internal.config.provided;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.lite.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
+import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
+
+/**
+ * Dataflow job configuration.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class InstanceProvidedDataflowJobConfiguration implements JobTypeConfiguration, JobInstanceProvided {
+
+ private final JobCoreConfiguration coreConfig;
+
+ private final JobType jobType = JobType.DATAFLOW;
+
+ private final String jobClass;
+
+ private final boolean streamingProcess;
+
+ private final ElasticJob jobInstance;
+}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/InstanceProvidedSimpleJobConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/InstanceProvidedSimpleJobConfiguration.java
new file mode 100644
index 0000000..03ff2d1
--- /dev/null
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/InstanceProvidedSimpleJobConfiguration.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.internal.config.provided;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.lite.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
+import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
+
+/**
+ * Simple job configuration.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class InstanceProvidedSimpleJobConfiguration implements JobTypeConfiguration, JobInstanceProvided {
+
+ private final JobCoreConfiguration coreConfig;
+
+ private final JobType jobType = JobType.SIMPLE;
+
+ private final String jobClass;
+
+ private final ElasticJob jobInstance;
+}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/JobInstanceProvided.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/JobInstanceProvided.java
new file mode 100644
index 0000000..3fe857a
--- /dev/null
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/provided/JobInstanceProvided.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.internal.config.provided;
+
+import org.apache.shardingsphere.elasticjob.lite.api.ElasticJob;
+
+/**
+ * Job instance provided.
+ */
+public interface JobInstanceProvided {
+
+ /**
+ * Get job instance.
+ *
+ * @return job instance
+ */
+ ElasticJob getJobInstance();
+}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/util/json/AbstractJobConfigurationGsonTypeAdapter.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/util/json/AbstractJobConfigurationGsonTypeAdapter.java
index d763278..c9e2b64 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/util/json/AbstractJobConfigurationGsonTypeAdapter.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/util/json/AbstractJobConfigurationGsonTypeAdapter.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConf
import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.handler.JobProperties;
+import org.apache.shardingsphere.elasticjob.lite.internal.config.provided.InstanceProvidedDataflowJobConfiguration;
import java.io.IOException;
import java.util.HashMap;
@@ -179,8 +180,13 @@ public abstract class AbstractJobConfigurationGsonTypeAdapter<T extends JobRootC
out.name("description").value(value.getTypeConfig().getCoreConfig().getDescription());
out.name("jobProperties").jsonValue(value.getTypeConfig().getCoreConfig().getJobProperties().json());
if (value.getTypeConfig().getJobType() == JobType.DATAFLOW) {
- DataflowJobConfiguration dataflowJobConfig = (DataflowJobConfiguration) value.getTypeConfig();
- out.name("streamingProcess").value(dataflowJobConfig.isStreamingProcess());
+ boolean streamingProcess;
+ if (value.getTypeConfig() instanceof InstanceProvidedDataflowJobConfiguration) {
+ streamingProcess = ((InstanceProvidedDataflowJobConfiguration) value.getTypeConfig()).isStreamingProcess();
+ } else {
+ streamingProcess = ((DataflowJobConfiguration) value.getTypeConfig()).isStreamingProcess();
+ }
+ out.name("streamingProcess").value(streamingProcess);
} else if (value.getTypeConfig().getJobType() == JobType.SCRIPT) {
ScriptJobConfiguration scriptJobConfig = (ScriptJobConfiguration) value.getTypeConfig();
out.name("scriptCommandLine").value(scriptJobConfig.getScriptCommandLine());
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/api/SpringJobScheduler.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/api/SpringJobScheduler.java
deleted file mode 100644
index 665bab0..0000000
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/api/SpringJobScheduler.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.lite.spring.api;
-
-import org.apache.shardingsphere.elasticjob.lite.api.ElasticJob;
-import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
-import org.apache.shardingsphere.elasticjob.lite.api.listener.ElasticJobListener;
-import org.apache.shardingsphere.elasticjob.lite.config.LiteJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.event.JobEventConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.reg.base.CoordinatorRegistryCenter;
-import org.apache.shardingsphere.elasticjob.lite.spring.job.util.AopTargetUtils;
-import org.springframework.beans.factory.DisposableBean;
-
-import java.util.Optional;
-
-/**
- * Job scheduler for spring.
- */
-public final class SpringJobScheduler extends JobScheduler implements DisposableBean {
-
- private final ElasticJob elasticJob;
-
- public SpringJobScheduler(final ElasticJob elasticJob, final CoordinatorRegistryCenter regCenter, final LiteJobConfiguration jobConfig, final ElasticJobListener... elasticJobListeners) {
- super(regCenter, jobConfig, getTargetElasticJobListeners(elasticJobListeners));
- this.elasticJob = elasticJob;
- }
-
- public SpringJobScheduler(final ElasticJob elasticJob, final CoordinatorRegistryCenter regCenter, final LiteJobConfiguration jobConfig,
- final JobEventConfiguration jobEventConfig, final ElasticJobListener... elasticJobListeners) {
- super(regCenter, jobConfig, jobEventConfig, getTargetElasticJobListeners(elasticJobListeners));
- this.elasticJob = elasticJob;
- }
-
- private static ElasticJobListener[] getTargetElasticJobListeners(final ElasticJobListener[] elasticJobListeners) {
- final ElasticJobListener[] result = new ElasticJobListener[elasticJobListeners.length];
- for (int i = 0; i < elasticJobListeners.length; i++) {
- result[i] = (ElasticJobListener) AopTargetUtils.getTarget(elasticJobListeners[i]);
- }
- return result;
- }
-
- @Override
- protected Optional<ElasticJob> createElasticJobInstance() {
- return Optional.ofNullable(elasticJob);
- }
-
- @Override
- public void destroy() {
- shutdown();
- }
-}
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java
index 7b288cb..a00048d 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common;
import com.google.common.base.Strings;
+import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.LiteJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.event.rdb.JobEventRdbConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.handler.JobProperties;
-import org.apache.shardingsphere.elasticjob.lite.spring.api.SpringJobScheduler;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -42,18 +42,8 @@ public abstract class AbstractJobBeanDefinitionParser extends AbstractBeanDefini
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
- BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class);
+ BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(JobScheduler.class);
factory.setInitMethodName("init");
- //TODO abstract subclass
- if ("".equals(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE))) {
- if ("".equals(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE))) {
- factory.addConstructorArgValue(null);
- } else {
- factory.addConstructorArgValue(BeanDefinitionBuilder.rootBeanDefinition(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE)).getBeanDefinition());
- }
- } else {
- factory.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE));
- }
factory.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.REGISTRY_CENTER_REF_ATTRIBUTE));
factory.addConstructorArgValue(createLiteJobConfiguration(parserContext, element));
BeanDefinition jobEventConfig = createJobEventConfig(element);
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java
index d75dd92..91b9dc4 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.dataflow;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.internal.config.provided.InstanceProvidedDataflowJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -33,7 +33,7 @@ public final class DataflowJobBeanDefinitionParser extends AbstractJobBeanDefini
@Override
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
- BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(DataflowJobConfiguration.class);
+ BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(InstanceProvidedDataflowJobConfiguration.class);
result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
if (Strings.isNullOrEmpty(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE))) {
result.addConstructorArgValue(parserContext.getRegistry().getBeanDefinition(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE)).getBeanClassName());
@@ -41,6 +41,11 @@ public final class DataflowJobBeanDefinitionParser extends AbstractJobBeanDefini
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE));
}
result.addConstructorArgValue(element.getAttribute(DataflowJobBeanDefinitionParserTag.STREAMING_PROCESS_ATTRIBUTE));
+ if (Strings.isNullOrEmpty(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE))) {
+ result.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE));
+ } else {
+ result.addConstructorArgValue(null);
+ }
return result.getBeanDefinition();
}
}
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java
index dbd93eb..dcddef3 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.simple;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.internal.config.provided.InstanceProvidedSimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -33,13 +33,18 @@ public final class SimpleJobBeanDefinitionParser extends AbstractJobBeanDefiniti
@Override
protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
- BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(SimpleJobConfiguration.class);
+ BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(InstanceProvidedSimpleJobConfiguration.class);
result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
if (Strings.isNullOrEmpty(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE))) {
result.addConstructorArgValue(parserContext.getRegistry().getBeanDefinition(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE)).getBeanClassName());
} else {
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE));
}
+ if (Strings.isNullOrEmpty(element.getAttribute(BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE))) {
+ result.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE));
+ } else {
+ result.addConstructorArgValue(null);
+ }
return result.getBeanDefinition();
}
}