You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "fengwuxp (via GitHub)" <gi...@apache.org> on 2026/03/10 06:04:20 UTC
[PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
fengwuxp opened a new pull request, #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508
Fixes #2506.
Changes proposed in this pull request:
- Add elasticjob-spring-boot4-starter module
- Add Spring Boot 4.x dependency adaptation
- Adjust the ElasticJobAutoConfiguration、ElasticJobTracingConfiguration and TracingProperties classes to adapt to Spring Boot 4.x.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "fengwuxp (via GitHub)" <gi...@apache.org>.
fengwuxp commented on PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#issuecomment-4035572584
CI encountered an error during the build process; let me see how to fix it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "fengwuxp (via GitHub)" <gi...@apache.org>.
fengwuxp commented on code in PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#discussion_r2915393792
##########
spring/boot4-starter/README.md:
##########
@@ -0,0 +1,93 @@
+# ElasticJob Spring Boot Starter
+
+## Getting Started
+
+### Add Dependencies
+
+```xml
+<dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-spring-boot4-starter</artifactId>
+ <version>${latest.version}</version>
+</dependency>
+```
+
+Tracing starter is optional.
+User can provide a bean of `TracingConfiguration` manually.
+```xml
+<dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-tracing-spring-boot-starter</artifactId>
+ <version>${latest.version}</version>
+</dependency>
+```
+
+### Implement a ElasticJob
+
+```java
+@Component
+public class SpringBootSimpleJob implements SimpleJob {
+
+ @Autowired
+ private FooRepository fooRepository;
+
+ @Override
+ public void execute(ShardingContext shardingContext) {
+ System.out.println(String.format("Item: %s | Time: %s | Thread: %s | %s",
+ shardingContext.getShardingItem(), new SimpleDateFormat("HH:mm:ss").format(new Date()), Thread.currentThread().getId(), "SIMPLE"));
+ List<Foo> data = fooRepository.findTodoData(shardingContext.getShardingParameter(), 10);
+ for (Foo each : data) {
+ fooRepository.setCompleted(each.getId());
+ }
+ }
+}
+```
+
+### Configure Registry Center, Jobs and Tracing Configuration
+
+`application.yml`
+```yaml
+elasticjob:
+ tracing:
+ type: RDB
+ regCenter:
+ serverLists: localhost:6181
+ namespace: elasticjob-springboot
+ jobs:
+ classed:
+ org.apache.shardingsphere.elasticjob.simple.job.SimpleJob:
+ - jobName: simpleJob
+ cron: 0/5 * * * * ?
+ shardingTotalCount: 3
+ shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou
+ org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob:
+ - jobName: dataflowJob
+ cron: 0/5 * * * * ?
+ shardingTotalCount: 3
+ shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou
+ typed:
+ SCRIPT:
+ - jobName: scriptJob
+ cron: 0/10 * * * * ?
+ shardingTotalCount: 3
+ props:
+ script.command.line: /home/sia/test/hello.sh
+```
+
+### Run it!
+
+Log fragments after started:
+```
+Item: 2 | Time: 14:18:00 | Thread: 391 | DATAFLOW FETCH
+Item: 0 | Time: 14:18:00 | Thread: 386 | DATAFLOW FETCH
+Item: 0 | Time: 14:18:00 | Thread: 387 | SIMPLE
+Item: 1 | Time: 14:18:00 | Thread: 389 | SIMPLE
+Item: 2 | Time: 14:18:00 | Thread: 393 | SIMPLE
+Item: 1 | Time: 14:18:00 | Thread: 388 | DATAFLOW FETCH
+Item: 1 | Time: 14:18:00 | Thread: 388 | DATAFLOW PROCESS
+Item: 0 | Time: 14:18:00 | Thread: 386 | DATAFLOW PROCESS
+Item: 2 | Time: 14:18:00 | Thread: 391 | DATAFLOW PROCESS
+SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":1}
+SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":2}
+SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":0}
+```
Review Comment:
<img width="2240" height="784" alt="image" src="https://github.com/user-attachments/assets/ded58334-c350-484e-9918-e56d5c0a3097" />
I added a blank line, but it doesn't seem to be showing up here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "fengwuxp (via GitHub)" <gi...@apache.org>.
fengwuxp commented on PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#issuecomment-4035640998
> This process is a bit difficult to explain.
>
> The approach on the https://github.com/apache/shardingsphere side is that CI operations build using JDK 11, while unit tests are still configured to run under JDK 8, although there are also CI configurations for JDK 11-JDK 25.
>
> This approach could be migrated to the Elasticjob side, where builds use JDK 17, while unit tests are still configured to run under JDK 8. This clearly requires a separate issue and pull request; if you don't have time to follow up, I will do so next weekend.
>
> update: This theoretically doesn't require changing the JDK8 runtime requirements, only the build-time requirements. Of course, it's impossible to avoid using JDK17 class files through reflection, which might make the implementation somewhat unusual.
Okay, I'm not very familiar with CI configuration. Could you please update me after you've finished so I can learn from it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#discussion_r2910653136
##########
spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.spring.boot.tracing;
+
+import com.zaxxer.hikari.HikariDataSource;
Review Comment:
`HikariDataSource` is referenced at class-load time, but `spring-boot-starter-jdbc` is declared as optional in the starter POM. If a consumer uses the starter without JDBC/Hikari on the classpath, this import can trigger `NoClassDefFoundError` when Spring loads the configuration class. Guard the RDB tracing configuration with `@ConditionalOnClass(HikariDataSource.class)` (and/or move the Hikari-dependent code into a nested `@Configuration` class annotated with `@ConditionalOnClass`).
##########
spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.spring.boot.tracing;
+
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.jdbc.autoconfigure.DataSourceProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.lang.Nullable;
+
+import javax.sql.DataSource;
+
+/**
+ * ElasticJob tracing auto configuration.
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableConfigurationProperties(TracingProperties.class)
+public class ElasticJobTracingConfiguration {
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = "RDB")
+ static class RDBTracingConfiguration {
+
+ /**
+ * Create a bean of tracing DataSource.
+ *
+ * @param tracingProperties tracing Properties
+ * @return tracing DataSource
+ */
+ @Bean("tracingDataSource")
+ public DataSource tracingDataSource(final TracingProperties tracingProperties) {
+ DataSourceProperties dataSource = tracingProperties.getDataSource();
+ if (dataSource == null) {
+ return null;
+ }
Review Comment:
Returning `null` from an `@Bean` method is error-prone (can result in a `NullBean` being registered and makes downstream injection/conditions ambiguous). Prefer making the bean conditional (e.g., `@ConditionalOnProperty` for the URL) so the bean is not registered at all when configuration is missing, or explicitly mark the factory method as `@Nullable` and ensure downstream logic handles the absence without relying on a `NullBean`.
##########
spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.spring.boot.tracing;
+
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.jdbc.autoconfigure.DataSourceProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.lang.Nullable;
+
+import javax.sql.DataSource;
+
+/**
+ * ElasticJob tracing auto configuration.
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableConfigurationProperties(TracingProperties.class)
+public class ElasticJobTracingConfiguration {
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = "RDB")
+ static class RDBTracingConfiguration {
+
+ /**
+ * Create a bean of tracing DataSource.
+ *
+ * @param tracingProperties tracing Properties
+ * @return tracing DataSource
+ */
+ @Bean("tracingDataSource")
+ public DataSource tracingDataSource(final TracingProperties tracingProperties) {
+ DataSourceProperties dataSource = tracingProperties.getDataSource();
+ if (dataSource == null) {
+ return null;
+ }
+ HikariDataSource tracingDataSource = new HikariDataSource();
+ tracingDataSource.setJdbcUrl(dataSource.getUrl());
+ BeanUtils.copyProperties(dataSource, tracingDataSource);
+ return tracingDataSource;
+ }
+
+ /**
+ * Create a bean of tracing configuration.
+ *
+ * @param dataSource required by constructor
+ * @param tracingDataSource tracing ataSource
+ * @return a bean of tracing configuration
+ */
+ @Bean
+ public TracingConfiguration<DataSource> tracingConfiguration(@Qualifier("dataSource") @Nullable final DataSource dataSource,
+ @Qualifier("tracingDataSource") @Nullable final DataSource tracingDataSource) {
+ if (dataSource == null && tracingDataSource == null) {
+ throw new IllegalArgumentException("Neither dataSource nor tracingDataSource bean is required");
Review Comment:
The exception message is misleading: the condition indicates at least one of the two beans is required/expected, but the message says “is required” for neither. Consider rewording to something like “Either dataSource or tracingDataSource bean is required” or “No DataSource available: define dataSource or elasticjob.tracing.dataSource”.
```suggestion
throw new IllegalArgumentException("Either dataSource or tracingDataSource bean is required");
```
##########
spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobBootstrapConfiguration.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.spring.boot.job;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap;
+import org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap;
+import org.apache.shardingsphere.elasticjob.spring.boot.tracing.TracingProperties;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.SmartInitializingSingleton;
+import org.springframework.beans.factory.config.SingletonBeanRegistry;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import java.util.Map;
+
+/**
+ * Job bootstrap configuration.
+ */
+@Slf4j
+public class ElasticJobBootstrapConfiguration implements SmartInitializingSingleton, ApplicationContextAware {
+
+ @Setter
+ private ApplicationContext applicationContext;
+
+ @Override
+ public void afterSingletonsInstantiated() {
+ log.info("creating Job Bootstrap Beans");
+ createJobBootstrapBeans();
+ log.info("Job Bootstrap Beans created.");
+ }
+
+ /**
+ * Create job bootstrap instances and register them into container.
+ */
+ public void createJobBootstrapBeans() {
+ ElasticJobProperties elasticJobProperties = applicationContext.getBean(ElasticJobProperties.class);
+ SingletonBeanRegistry singletonBeanRegistry = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
+ CoordinatorRegistryCenter registryCenter = applicationContext.getBean(CoordinatorRegistryCenter.class);
+ TracingConfiguration<?> tracingConfig = getTracingConfiguration();
+ constructJobBootstraps(elasticJobProperties, singletonBeanRegistry, registryCenter, tracingConfig);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private TracingConfiguration<?> getTracingConfiguration() {
+ Map<String, TracingConfiguration> tracingConfigurationBeans = applicationContext.getBeansOfType(TracingConfiguration.class);
+ if (tracingConfigurationBeans.isEmpty()) {
+ return null;
+ }
+ if (1 == tracingConfigurationBeans.size()) {
+ return tracingConfigurationBeans.values().iterator().next();
+ }
+ throw new BeanCreationException("More than one [org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration] beans found. "
+ + "Consider disabling [org.apache.shardingsphere.elasticjob.tracing.boot.ElasticJobTracingAutoConfiguration].");
+ }
+
+ private void constructJobBootstraps(final ElasticJobProperties elasticJobProperties, final SingletonBeanRegistry singletonBeanRegistry,
+ final CoordinatorRegistryCenter registryCenter, final TracingConfiguration<?> tracingConfig) {
+ for (Map.Entry<String, ElasticJobConfigurationProperties> entry : elasticJobProperties.getJobs().entrySet()) {
+ ElasticJobConfigurationProperties jobConfigurationProperties = entry.getValue();
+ Preconditions.checkArgument(null != jobConfigurationProperties.getElasticJobClass()
+ || !Strings.isNullOrEmpty(jobConfigurationProperties.getElasticJobType()),
+ "Please specific [elasticJobClass] or [elasticJobType] under job configuration.");
Review Comment:
Correct the typo 'specific' to 'specify' in the error message.
```suggestion
"Please specify [elasticJobClass] or [elasticJobType] under job configuration.");
```
##########
spring/boot4-starter/src/main/resources/META-INF/spring.provides:
##########
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+provides: elasticjob-spring-boot-starter
Review Comment:
This Boot 4 starter module declares it “provides” `elasticjob-spring-boot-starter`, which appears to be the Boot 2/3 starter name. To avoid confusing tooling and users, update it to `elasticjob-spring-boot4-starter` (or the intended Boot 4 artifact identifier).
```suggestion
provides: elasticjob-spring-boot4-starter
```
##########
spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/job/impl/AnnotationCustomJob.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.spring.boot.job.fixture.job.impl;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobProp;
+import org.apache.shardingsphere.elasticjob.spi.executor.item.param.ShardingContext;
+import org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.job.CustomJob;
+import org.springframework.transaction.annotation.Transactional;
+
+@Slf4j
+@Transactional(rollbackFor = Exception.class)
+@ElasticJobConfiguration(
+ jobName = "annotationCustomJobSchedule",
+ description = "desc",
+ shardingTotalCount = 3,
+ shardingItemParameters = "0=a,1=b,2=c",
+ cron = "*/1 * * * * ?",
+ props = {
+ @ElasticJobProp(key = "print.title", value = "test title"),
+ @ElasticJobProp(key = "print.content", value = "test content")
+ })
+public class AnnotationCustomJob implements CustomJob {
+
+ @Getter
+ private static volatile boolean completed;
+
+ @Override
+ public void execute(final ShardingContext shardingContext) {
+ log.info("AnnotationCustomJob execut");
Review Comment:
Correct the log message typo 'execut' to 'execute'.
```suggestion
log.info("AnnotationCustomJob execute");
```
##########
spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.spring.boot.tracing;
+
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.jdbc.autoconfigure.DataSourceProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.lang.Nullable;
+
+import javax.sql.DataSource;
+
+/**
+ * ElasticJob tracing auto configuration.
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableConfigurationProperties(TracingProperties.class)
+public class ElasticJobTracingConfiguration {
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = "RDB")
+ static class RDBTracingConfiguration {
+
+ /**
+ * Create a bean of tracing DataSource.
+ *
+ * @param tracingProperties tracing Properties
+ * @return tracing DataSource
+ */
+ @Bean("tracingDataSource")
+ public DataSource tracingDataSource(final TracingProperties tracingProperties) {
+ DataSourceProperties dataSource = tracingProperties.getDataSource();
+ if (dataSource == null) {
+ return null;
+ }
+ HikariDataSource tracingDataSource = new HikariDataSource();
+ tracingDataSource.setJdbcUrl(dataSource.getUrl());
+ BeanUtils.copyProperties(dataSource, tracingDataSource);
+ return tracingDataSource;
+ }
+
+ /**
+ * Create a bean of tracing configuration.
+ *
+ * @param dataSource required by constructor
+ * @param tracingDataSource tracing ataSource
Review Comment:
Correct the Javadoc typo 'ataSource' to 'dataSource'.
```suggestion
* @param tracingDataSource tracing dataSource
```
##########
spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobBootstrapConfiguration.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.spring.boot.job;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap;
+import org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap;
+import org.apache.shardingsphere.elasticjob.spring.boot.tracing.TracingProperties;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.SmartInitializingSingleton;
+import org.springframework.beans.factory.config.SingletonBeanRegistry;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import java.util.Map;
+
+/**
+ * Job bootstrap configuration.
+ */
+@Slf4j
+public class ElasticJobBootstrapConfiguration implements SmartInitializingSingleton, ApplicationContextAware {
+
+ @Setter
+ private ApplicationContext applicationContext;
+
+ @Override
+ public void afterSingletonsInstantiated() {
+ log.info("creating Job Bootstrap Beans");
+ createJobBootstrapBeans();
+ log.info("Job Bootstrap Beans created.");
+ }
+
+ /**
+ * Create job bootstrap instances and register them into container.
+ */
+ public void createJobBootstrapBeans() {
+ ElasticJobProperties elasticJobProperties = applicationContext.getBean(ElasticJobProperties.class);
+ SingletonBeanRegistry singletonBeanRegistry = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
+ CoordinatorRegistryCenter registryCenter = applicationContext.getBean(CoordinatorRegistryCenter.class);
+ TracingConfiguration<?> tracingConfig = getTracingConfiguration();
+ constructJobBootstraps(elasticJobProperties, singletonBeanRegistry, registryCenter, tracingConfig);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private TracingConfiguration<?> getTracingConfiguration() {
+ Map<String, TracingConfiguration> tracingConfigurationBeans = applicationContext.getBeansOfType(TracingConfiguration.class);
+ if (tracingConfigurationBeans.isEmpty()) {
+ return null;
+ }
+ if (1 == tracingConfigurationBeans.size()) {
+ return tracingConfigurationBeans.values().iterator().next();
+ }
+ throw new BeanCreationException("More than one [org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration] beans found. "
+ + "Consider disabling [org.apache.shardingsphere.elasticjob.tracing.boot.ElasticJobTracingAutoConfiguration].");
Review Comment:
This error message references old/incorrect package and auto-configuration class names that don’t match the Boot 4 starter classes in this module. Update it to point to the actual `TracingConfiguration` type and the relevant configuration class to disable (e.g., the starter’s tracing auto-configuration) so users can act on it.
```suggestion
throw new BeanCreationException("More than one [org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration] beans found. "
+ "Consider disabling [org.apache.shardingsphere.elasticjob.spring.boot.tracing.ElasticJobTracingAutoConfiguration].");
```
##########
spring/boot4-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
Review Comment:
JSON comments (`/* ... */`) are not valid JSON and can break strict parsers/tools that read Spring Boot configuration metadata. Consider removing the comment block (or moving licensing to a separate LICENSE/NOTICE mechanism) to ensure the metadata is universally parseable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#issuecomment-4035650805
> Okay, I'm not very familiar with CI configuration. Could you please update me after you've finished so I can learn from it?
No problem, but the final CI PR might not be as complicated as you think.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on code in PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#discussion_r2912628728
##########
spring/boot4-starter/README.md:
##########
@@ -0,0 +1,93 @@
+# ElasticJob Spring Boot Starter
Review Comment:
Perhaps you should put the Chinese and English documentation in two new files under https://github.com/apache/shardingsphere-elasticjob/tree/master/docs%2Fcontent%2Fuser-manual%2Fconfiguration . I don't think anyone would notice if the documentation was placed next to `pom.xml`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "fengwuxp (via GitHub)" <gi...@apache.org>.
fengwuxp commented on code in PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#discussion_r2915353880
##########
spring/boot4-starter/README.md:
##########
@@ -0,0 +1,93 @@
+# ElasticJob Spring Boot Starter
Review Comment:
The spring-boot-starter.xx.md file now includes instructions related to boot4-starter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on code in PR #2508:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508#discussion_r2910581861
##########
spring/boot4-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
Review Comment:
Aha, JSON doesn't need a license.
##########
spring/boot4-starter/README.md:
##########
@@ -0,0 +1,93 @@
+# ElasticJob Spring Boot Starter
+
+## Getting Started
+
+### Add Dependencies
+
+```xml
+<dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-spring-boot4-starter</artifactId>
+ <version>${latest.version}</version>
+</dependency>
+```
+
+Tracing starter is optional.
+User can provide a bean of `TracingConfiguration` manually.
+```xml
+<dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-tracing-spring-boot-starter</artifactId>
+ <version>${latest.version}</version>
+</dependency>
+```
+
+### Implement a ElasticJob
+
+```java
+@Component
+public class SpringBootSimpleJob implements SimpleJob {
+
+ @Autowired
+ private FooRepository fooRepository;
+
+ @Override
+ public void execute(ShardingContext shardingContext) {
+ System.out.println(String.format("Item: %s | Time: %s | Thread: %s | %s",
+ shardingContext.getShardingItem(), new SimpleDateFormat("HH:mm:ss").format(new Date()), Thread.currentThread().getId(), "SIMPLE"));
+ List<Foo> data = fooRepository.findTodoData(shardingContext.getShardingParameter(), 10);
+ for (Foo each : data) {
+ fooRepository.setCompleted(each.getId());
+ }
+ }
+}
+```
+
+### Configure Registry Center, Jobs and Tracing Configuration
+
+`application.yml`
+```yaml
+elasticjob:
+ tracing:
+ type: RDB
+ regCenter:
+ serverLists: localhost:6181
+ namespace: elasticjob-springboot
+ jobs:
+ classed:
+ org.apache.shardingsphere.elasticjob.simple.job.SimpleJob:
+ - jobName: simpleJob
+ cron: 0/5 * * * * ?
+ shardingTotalCount: 3
+ shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou
+ org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob:
+ - jobName: dataflowJob
+ cron: 0/5 * * * * ?
+ shardingTotalCount: 3
+ shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou
+ typed:
+ SCRIPT:
+ - jobName: scriptJob
+ cron: 0/10 * * * * ?
+ shardingTotalCount: 3
+ props:
+ script.command.line: /home/sia/test/hello.sh
+```
+
+### Run it!
+
+Log fragments after started:
+```
+Item: 2 | Time: 14:18:00 | Thread: 391 | DATAFLOW FETCH
+Item: 0 | Time: 14:18:00 | Thread: 386 | DATAFLOW FETCH
+Item: 0 | Time: 14:18:00 | Thread: 387 | SIMPLE
+Item: 1 | Time: 14:18:00 | Thread: 389 | SIMPLE
+Item: 2 | Time: 14:18:00 | Thread: 393 | SIMPLE
+Item: 1 | Time: 14:18:00 | Thread: 388 | DATAFLOW FETCH
+Item: 1 | Time: 14:18:00 | Thread: 388 | DATAFLOW PROCESS
+Item: 0 | Time: 14:18:00 | Thread: 386 | DATAFLOW PROCESS
+Item: 2 | Time: 14:18:00 | Thread: 391 | DATAFLOW PROCESS
+SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":1}
+SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":2}
+SCRIPT Job: {"jobName":"scriptJob","taskId":"scriptJob@-@0,1,2@-@READY@-@192.168.3.233@-@28250","shardingTotalCount":3,"jobParameter":"","shardingItem":0}
+```
Review Comment:
Please add a new blank line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(spring): Add Spring Boot 4 Starter Support [shardingsphere-elasticjob]
Posted by "terrymanu (via GitHub) via notifications" <no...@shardingsphere.apache.org>.
terrymanu closed pull request #2508: feat(spring): Add Spring Boot 4 Starter Support
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2508
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org