I have created a multimodule Springboot gradle project and the project structure is as below. When I run the MultimoduleApplication.class, the scheduled method in the child module is not getting executed at all.
| --src | --com.test.multimodule(package) | --MultimoduleApplication(Class with Main method and with @SpringBootApplication) --build.gradle (added dependency for child module) --settings.gradle (included the child module) child module | --src | --com.test.child(package) | --Child Application(Class with Main method and with @SpringBootApplication) --ScheduleClass(Class with a @Scheduled method) --resources | --application.properties
Schedule method class from the child module.
package com.test.child;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class ScheduleClass {
@Value("${custom.property1}")
private String customString;
@Scheduled(fixedDelay = 5000, initialDelay = 10000)
public void publishEventStoreRecords()
{
System.out.println("Testing " + customString);
}
}
Main class from the root project that I am running
package com.test.multimodule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = "com.test")
public class MultimoduleApplication {
public static void main(String[] args) {
SpringApplication.run(MultimoduleApplication.class, args);
}
}
root project's build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.4'
id 'io.spring.dependency-management' version '1.1.3'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
implementation project(':child')
}
rootProject.name = 'multimodule'
include 'child'
I tried adding @ComponentScan on the rootproject's Main class and also made sure to add @Component annotation on the scheduled methods's class in child module.
I am expecting the schedmethod in the child module to execute automatically at the scheduled intervals after I ran the rootproject's Main class(MultimoduleApplication)