In a spring boot project I'm working on, we have a lot of classes that extend Consumer
, Processor
, or Producer
custom abstract classes. All these concrete extension classes are also annotated with @Component
, @ConditionalOnProperty
and usually @Profile
as well.
I just started learning about Java annotations and was wondering if it's possible (at all) to simplify my above scenario by creating custom @Consumer
, @Processor
, and @Producer
annotations, such that doing
@Consumer(profile = "some_profile", conditionalOnName = "some_name", conditionalOnValue = "some_value")
public class MyCustomConsumer {
// Abstract methods implementation
}
is the same as
@Component
@ConditionalOnProperty(name = "some_name", havingValue = "some_value")
@Profile("some_profile")
public class MyCustomConsumer extends Consumer {
// Abstract methods implementation
}
and the missing abstract methods inherited from Consumer
are enforced on MyCustomConsumer
(meaning the compiler will complain that those methods are not implemented).
Seems like a very long shot in getting something like this to work (as my research into Java annotations hasn't shown any viable option), but seeing how Lombok can add code to my code without modifying the file, I thought I'd ask.
Is this possible?