Configuring custom conditional bean instantiations

In the previous example, you learned how to get the basic Spring Boot Starter going. On the inclusion of the jar in the application classpath, the DbCountRunner bean will be created automatically and added to the application context. In the very first recipe of this chapter, we have also seen that Spring Boot has an ability to do conditional configurations depending on a few conditions, such as the presence of specific classes in the classpath, existence of a bean, and others.

For this recipe, we will enhance our starter with a conditional check. This will create the instance of DbCountRunner only if no other bean instance of this class has already been created and added to the application context. ...

Get Spring Boot Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.