對於spring配置的配置註解(annotations)是否比xml更好?
對於spring配置的配置註解(annotations)是否比xml更好?
原文:
Are annotations better than XML for configuring Spring?
The introduction of annotation-based configurations raised the question of whether this approach is 'better' than XML. The short answer is it depends. The long answer is that each approach has its pros and cons, and usually it is up to the developer to decide which strategy suits her better. Due to the way they are defined, annotations provide a lot of context in their declaration, leading to shorter and more concise configuration. However, XML excels at wiring up components without touching their source code or recompiling them. Some developers prefer having the wiring close to the source while others argue that annotated classes are no longer POJOs and, furthermore, that the configuration becomes decentralized and harder to control.
No matter the choice, Spring can accommodate both styles and even mix them together. It's worth pointing out that through its
JavaConfig option, Spring allows annotations to be used in a non-invasive way, without touching the target components source code and that in terms of tooling, all configuration styles are supported by the
譯文
對於spring配置的配置註解(annotations)是否比xml更好?
基於註解的spring配置的介紹提出了一個問題,是否這種方式比xml的配置方式更好。簡單的回答是看情況。完整的回答是每種方式都有自己的有點和缺點,這要看開發者決定用哪種方式更適合自己。根據他的決定,註解方式在他的宣告中提供了大量的上下文,從而實現了更短和更方便的配置。但是,xml的方式在不需要解除程式碼和重新編譯的情況下裝配元件表現的更出色。一些開發者傾向於封閉的原始碼,而另一些開發者排斥使用註解類,因為這樣不再POJO,而且這樣的配置方式變的不再集中管理並且很難控制。不管選擇哪種方式,