Create better Spring libraries with @Enable… Annotations
You can find the sample code in the following repo: https://github.com/gorkemgok/enabler-annotation-example
Sometimes, we create libraries to make some functionalities reusable for multiple applications. When those libraries have some beans to be registered in the spring context, the developers tend to use @ComponentScan or @Import annotations in the application. By doing this, the application is made highly dependent on the library's internal structure and the author of the library loses control over the design.
Let’s say we have a spring rest application and we want to create a library to add some common headers (such as X-Host and X-Trace-Id) to the responses.
To do that we would have two request filters in our library as followings: