feat(spring): Add Spring Boot 4 Starter Support#2508
Conversation
linghengqian
left a comment
There was a problem hiding this comment.
- The code style is handled in a separate Maven profile. The PR did not pass the code formatting validation. You can execute first
./mvnw spotless:apply -Pcheck -T1C. Then execute./mvnw checkstyle:check -Pcheck -T1Cto manually adjust to repair the CI.
There was a problem hiding this comment.
Pull request overview
Adds a new elasticjob-spring-boot4-starter module and Spring Boot 4–compatible auto-configuration, including registry center, tracing, snapshot service support, and accompanying tests/resources.
Changes:
- Added
boot4-starterMaven module and introduced a Spring Boot 4 dependencies BOM property. - Implemented Boot 4 starter auto-configuration (registry center, job bootstrap creation, schedule startup runner, tracing, snapshot).
- Added Boot 4 starter tests, fixtures, SPI service registrations, and configuration metadata/docs.
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| spring/pom.xml | Registers the new boot4-starter module in the Spring reactor build. |
| pom.xml | Adds a property for the Spring Boot 4 BOM version. |
| spring/boot4-starter/pom.xml | New Boot 4 starter module POM with dependencies and test setup. |
| spring/boot4-starter/README.md | Adds usage documentation for the Boot 4 starter. |
| spring/boot4-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports | Registers Boot 3+/4-style auto-configuration import entry. |
| spring/boot4-starter/src/main/resources/META-INF/spring.factories | Adds legacy auto-configuration registration metadata. |
| spring/boot4-starter/src/main/resources/META-INF/spring.provides | Declares the “provides” metadata for the starter. |
| spring/boot4-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json | Adds IDE metadata for ElasticJob Boot 4 properties. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobAutoConfiguration.java | Main Boot 4 auto-configuration entry point importing sub-configurations. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobBootstrapConfiguration.java | Creates and registers job bootstrap beans from properties at startup. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ScheduleJobBootstrapStartupRunner.java | Schedules ScheduleJobBootstrap beans on application startup. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobProperties.java | Adds top-level elasticjob.jobs property binding. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobConfigurationProperties.java | Adds per-job configuration binding + conversion to JobConfiguration. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/ZookeeperProperties.java | Adds registry center property binding and conversion to ZookeeperConfiguration. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/ElasticJobRegistryCenterConfiguration.java | Creates and initializes ZookeeperRegistryCenter from properties. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/SnapshotServiceProperties.java | Adds snapshot service property binding. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfiguration.java | Conditionally creates and starts SnapshotService. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingProperties.java | Adds tracing property binding, including nested datasource config. |
| spring/boot4-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java | Adds tracing datasource + TracingConfiguration beans for RDB tracing. |
| spring/boot4-starter/src/test/resources/logback-test.xml | Provides test logging configuration for the new module. |
| spring/boot4-starter/src/test/resources/application-tracing.yml | Test profile config for tracing scenarios. |
| spring/boot4-starter/src/test/resources/application-snapshot.yml | Test profile config for snapshot service scenarios. |
| spring/boot4-starter/src/test/resources/application-elasticjob.yml | Test profile config for core ElasticJob starter scenarios. |
| spring/boot4-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.spi.listener.ElasticJobListener | Registers test listener SPI implementations. |
| spring/boot4-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.spi.executor.item.type.TypedJobItemExecutor | Registers test typed executor SPI implementation. |
| spring/boot4-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.spi.executor.item.type.ClassedJobItemExecutor | Registers test classed executor SPI implementation. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingConfigurationTest.java | Validates tracing beans are not created when RDB tracing config is absent. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java | Validates snapshot service auto-configuration behavior. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/ZookeeperPropertiesTest.java | Unit tests ZookeeperProperties conversion to ZookeeperConfiguration. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java | Integration test covering registry center, tracing, jobs, and bootstraps. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootScannerTest.java | Integration test validating @ElasticJobScan discovery + schedule bootstrap. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobConfigurationPropertiesTest.java | Unit tests job configuration properties conversion. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/repository/BarRepository.java | Test repository interface used by test job fixture. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/repository/impl/BarRepositoryImpl.java | Test repository implementation used by test job fixture. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/listener/NoopElasticJobListener.java | Test listener fixture SPI implementation. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/listener/LogElasticJobListener.java | Test listener fixture SPI implementation with logging. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/job/CustomJob.java | Test job interface used by classed executor + fixtures. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/job/impl/CustomTestJob.java | Test job fixture used by property-based job definition. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/job/impl/AnnotationCustomJob.java | Test job fixture used by annotation scanning test. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/executor/PrintJobProperties.java | Constants used by the typed job executor fixture. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/executor/PrintJobExecutor.java | Test typed job executor SPI implementation. |
| spring/boot4-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/executor/CustomClassedJobExecutor.java | Test classed job executor SPI implementation. |
Comments suppressed due to low confidence (1)
spring/boot4-starter/src/test/resources/application-elasticjob.yml:1
timeZomeis a typo and won’t bind toElasticJobConfigurationProperties.timeZone, so the timezone setting will be ignored. Rename the key totimeZone.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| package org.apache.shardingsphere.elasticjob.spring.boot.tracing; | ||
|
|
||
| import com.zaxxer.hikari.HikariDataSource; |
There was a problem hiding this 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).
| @Bean("tracingDataSource") | ||
| public DataSource tracingDataSource(final TracingProperties tracingProperties) { | ||
| DataSourceProperties dataSource = tracingProperties.getDataSource(); | ||
| if (dataSource == null) { | ||
| return null; | ||
| } |
There was a problem hiding this 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.
| 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"); |
There was a problem hiding this 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”.
| throw new IllegalArgumentException("Neither dataSource nor tracingDataSource bean is required"); | |
| throw new IllegalArgumentException("Either dataSource or tracingDataSource bean is required"); |
| throw new BeanCreationException("More than one [org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration] beans found. " | ||
| + "Consider disabling [org.apache.shardingsphere.elasticjob.tracing.boot.ElasticJobTracingAutoConfiguration]."); |
There was a problem hiding this 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.
| throw new BeanCreationException("More than one [org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration] beans found. " | |
| + "Consider disabling [org.apache.shardingsphere.elasticjob.tracing.boot.ElasticJobTracingAutoConfiguration]."); | |
| 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]."); |
| ElasticJobConfigurationProperties jobConfigurationProperties = entry.getValue(); | ||
| Preconditions.checkArgument(null != jobConfigurationProperties.getElasticJobClass() | ||
| || !Strings.isNullOrEmpty(jobConfigurationProperties.getElasticJobType()), | ||
| "Please specific [elasticJobClass] or [elasticJobType] under job configuration."); |
There was a problem hiding this comment.
Correct the typo 'specific' to 'specify' in the error message.
| "Please specific [elasticJobClass] or [elasticJobType] under job configuration."); | |
| "Please specify [elasticJobClass] or [elasticJobType] under job configuration."); |
|
|
||
| @Override | ||
| public void execute(final ShardingContext shardingContext) { | ||
| log.info("AnnotationCustomJob execut"); |
There was a problem hiding this comment.
Correct the log message typo 'execut' to 'execute'.
| log.info("AnnotationCustomJob execut"); | |
| log.info("AnnotationCustomJob execute"); |
| * Create a bean of tracing configuration. | ||
| * | ||
| * @param dataSource required by constructor | ||
| * @param tracingDataSource tracing ataSource |
There was a problem hiding this comment.
Correct the Javadoc typo 'ataSource' to 'dataSource'.
| * @param tracingDataSource tracing ataSource | |
| * @param tracingDataSource tracing dataSource |
…oot Starter => ElasticJob Spring Boot4 Starter
|
CI encountered an error during the build process; let me see how to fix it. Based on the error, the boot4-starter build should be ignored in a JDK 8 environment. Should I adjust the CI configuration? But I don't know how. |
There was a problem hiding this comment.
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? |
No problem, but the final CI PR might not be as complicated as you think. |
linghengqian
left a comment
There was a problem hiding this comment.
Late reply. #2511 has been merged.
The current PR needs to be rebased to the latest commit. Specifically, you need to use Junit5 @EnabledForJreRange(min = JRE.JAVA_17) in all unit test classes of the new Maven module, and mark the output artifact in the pom.xml of the new Maven module as JDK 17 bytecode.
Fixes #2506.
Changes proposed in this pull request: