注意3(来自 Javaworld.com.tw)
----------------------------------------------------------------------------------------------------------
Metadata Annotation vs Deployment Descriptor XML 的部分
@方面, 你可以x衿渲幸环N碓O定你的 EJB 相P配置c Resources ,
不一定完全需要使用 @Annotation !
如果你之前大量裼 XDoclet , 你就容^容易接受 @Annotation 的^念
resources 槭颤N要裼 XML ?! @是大多倒こ的思考行楸恢暗Framework 框架住了. f真的, _始的r候我也有c排斥, ^ saijone 的指c解f, 我X得 annotation is better
只是, 你楹我懦饽
下面是我的解
1. Compiling-Time Check
You can find the wrong setting in metadata annotations in compling-time, and u can't find it when u set each resource in the deployment descriptor, ( it will display error when u deploy it ).
2. Developing Simplification
Yap, use annotation, u just need one main BeanClass + BusinessInterface without any deployment descriptor (XML), when u wanna modify or setting some other resources in xml editing , u need another powerful tool like "XMLspy" or etc..
3. IDE integration
When u use the annotation with IDE ( new version which supported to JDK1.5 or Java EE 5.0 ) , u can ez to insert or modify ur annotation in the java files, Don't feel sucker, I think it is a great design in Java EE 5.0
You can view some opensources for IDE , ex, NetBeans or Eclipse!
4. You won't modify any resources in ur XML
Yap, XML is a great design for dynamic deploy for every great design.
if u need to change once and once, please use xml, *HOWEVER*, can u tell me , when u deploy one system to production mode , how many times u ever modified the deployment descriptors ?
so that , u alos can read the JSRs for getting more knowledge in annotation
JSR 175
JSR 181
JSR 220
JSR 250
and etc..
----------------------------------------------------------------------------------------------------------
注意4(来自 Javaworld.com.tw)
----------------------------------------------------------------------------------------------------------
我想, Bill Burke (JBoss EJB team)
http://www.theserverside.com/news/thread.tss?thread_id=33525
他了@Nr when to use Annotation vs whe to use XML
http://jboss.org/jbossBlog/blog/bburke/?permalink=When_to_use_annotations.txt
他的意思主要是, 你在O或修改的r候都绊到你的 Metadata ( 原本可能是在 XML 之中 ) 那N, 你就使用 Annotation 是比^好的x, 因 annotation U容易去淼. 你 "可y性 (portable)" 或 "{整性(Configurable)" 放在比^先的考量, 那N就使用 XML 去O定你的 Resource !
K且在一些 comment 的研x上 ( source codes are the best document ! )
例如 @OneToMany(mappedBy="item") 就可以清楚地定xPS, 比起
/** comments */ K且 XML 看, 菀自S多.
1. 的_, 你要O定每 Method 的r候, 程式@得臃[
但是如果 IDE @Annotation 可以O定槟撤N特殊的色彩甚至[藏,
也S可以解Q你的@}.
2. Interceptors 定x在各 class 之中, 相Φ那r, 你也O定在各 xml 中, 回到 Bill Bruke's Role, 如果你有C薷s不影到原有程式, 那N就裼 deployment descriptors 去O定 AOP !
for examples :
<interceptor-class>com.softleader.interceptors.CustomerAudit</interceptor-class>
<around-invoke-method>makeSomeAuditing</around-invoke-method>
其我F在的, 2004 年在 TheServerSide 就已 JSR-175 Metadata 有一番口舌之
http://www.theserverside.com/news/thread.tss?thread_id=25465
到底是不是 ugly syntax ?! 看你自己吧