First, we will comment out the content of the spring.factories file located in db-count-starter/src/main/resources in the root of our project, as follows:
Next, we will need to create the meta-annotation. We will create a new file named EnableDbCounting.java in the db-count-starter/src/main/java/com/example/bookpubstarter/dbcount directory in the root of our project with the following content:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(DbCountAutoConfiguration.class)
@Documented
public @interface EnableDbCounting {
}
We will now add the @EnableDbCounting annotation to our BookPubApplication class and also remove the dbCountRunner(...) method from it, as shown in the following snippet:
@SpringBootApplication
@EnableScheduling
@EnableDbCounting
public class BookPubApplication {
public static void main(String[] args) {
SpringApplication.run(BookPubApplication.class, args);
}
@Bean
public StartupRunner schedulerRunner() {
return new StartupRunner();
}
}
Start the application by running ./gradlew clean bootRun.