What are the Pros/Cons of Annotations (non-compiler) compared to xml config files

后端 未结 3 946
情话喂你
情话喂你 2020-12-30 02:21

When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have the possibility to make my configuration via an xml-file or put annotations directly in my clas

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 03:13

    If you're writing an API, then a word of warning: Annotations can leak out into your public interface which can be unbelievably infuriating.

    I'm currently working with APIs where the API vendor has peppered his implementation with Spring MBean annotations, which suddenly means I have a dependency upon the Spring libraries, despite the possibility I might not need to use Spring at all :(

    (Of course, if your API was an extension to Spring itself, this might be a valid assumption.)

提交回复
热议问题