Book Image

Spring Boot Cookbook

By : Alex Antonov
Book Image

Spring Boot Cookbook

By: Alex Antonov

Overview of this book

Table of Contents (15 chapters)
Spring Boot Cookbook
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Using custom @Enable* annotations to toggle configurations


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.

How to do it…

  1. 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:

    #org.springframework.boot.autoconfigure.EnableAutoConfiguration =\
    #org.test.bookpubstarter.dbcount.DbCountAutoConfiguration
  2. Next, we will need to create the meta-annotation. We will create a new file named EnableDbCounting.java...