还是来看看专家说的话吧!
Bill Burke has written up four simple rules for when to use annotations instead of XML, based on his experience with JBoss’ EJB3 implementation. They are:
- Use an annotation if the metadata you are applying changes the design of your class.
- Use an annotation if the metadata changes the design of code interacting with your class.
- If your application needs to be portable between app-servers or databases, don't use an annotation that will not allow you to be portable.
- Use XML when you want to configure on a per-deployment basis.