I want to know how Java generates annotation implementation like @Mapper and @FeignClient. Does It generates an implementation class in runtime?
Thanks.
Know how Java generates an implementation for an interface in runtime.
I want to know how Java generates annotation implementation like @Mapper and @FeignClient. Does It generates an implementation class in runtime?
Thanks.
Know how Java generates an implementation for an interface in runtime.
Java does not do anything when it comes to Annotation-based class generation. The magic behind these generations is the libraries themselves.
For example, MapStruct goes through all the classes and handles those with a @Mapper
Annotation. This is achieved through annotation processing and the Java Annotation Processing API. You can also configure how you want to make your generated classes available to the application (e.g. @Mapper(componentModel = "spring")
). In Spring the generated Mapper will be turned into a Spring Bean and will be associated with the Mapper (Interface) you autowire/inject in your other Spring Beans.
In JavaEE Context, it is basically the same thing, it's just that the injection is achieved a bit differently (e.g. CDI).
I have no experience with feign
, but I think it should use a similar approach.