Allowing Spring Boot to automatically evaluate the classpath and detected configurations that are found there makes it very quick and easy to get a simple application going. However, there are times when we want to provide the configuration classes but require consumers of the starter library to explicitly enable such a configuration rather than relying on Spring Boot to decide automatically if it should be included or not.
We will modify our previous recipe to enable the starter via a meta-annotation rather than using the spring.factories
route.
First, we will comment out the content of the
spring.factories
file located indb-count-starter/src/main/resources
in the root of our project, as follows:#org.springframework.boot.autoconfigure.EnableAutoConfiguration =\ #org.test.bookpubstarter.dbcount.DbCountAutoConfiguration
Next, we will need to create the meta-annotation. We will create a new file named
EnableDbCounting.java...