Arguments Against Annotations(反对注解的论点)
问题描述
我的团队正在迁移到 Spring 3.0,有些人希望开始将所有内容都迁移到 Annotations 中.当我看到一个具有这样的方法的类时,我的直觉(代码味道?)真的很糟糕:(只是一个例子 - 不是所有真正的注释)
My team is moving to Spring 3.0 and there are some people who want to start moving everything into Annotations. I just get a really bad feeling in my gut (code smell?) when I see a class that has methods like this: (just an example - not all real annotations)
@Transaction
@Method("GET")
@PathElement("time")
@PathElement("date")
@Autowired
@Secure("ROLE_ADMIN")
public void manage(@Qualifier('time')int time) {
...
}
我只是落后于时代,还是这一切在其他人看来都是一个可怕的想法?而不是使用像继承和多态这样的OO概念,现在一切都按照约定或通过注释.我只是不喜欢它.必须重新编译所有代码来更改 IMO 的配置似乎是错误的.但这似乎是一切(尤其是春天)的方式.我应该只是克服它"还是应该回击并尝试让我们的代码尽可能地免费?
Am I just behind the times, or does this all seem like a horrible idea to anyone else? Rather then using OO concepts like inheritance and polymorphism everything is now by convention or through annotations. I just don't like it. Having to recompile all the code to change things that IMO are configuration seems wrong. But it seems to be the way everything (especially Spring) is going. Should I just "get over it" or should I push back and try to keep our code as annotation free as possible?
推荐答案
其实我觉得你内心的不好感觉更多是因为像这种混合配置和代码的注解.
Actually I think that the bad feeling in your gut against has more to do with Annotations like this mixing configuration with code.
我个人感觉和你一样,我更愿意将配置(例如事务定义、路径元素、控制器应该映射到的 URL 等)留在代码库本身和外部 Spring 之外XML 上下文文件.
Personally I feel the same way as you do, I would prefer to leave configuration (such as transaction definitions, path elements, URLs that a controller should be mapped to, etc.) outside of the code base itself and in external Spring XML context files.
我认为,虽然这里的正确方法归结为意见和您更喜欢哪种方法 - 我预测一半的社区会同意注释方法,另一半会同意外部配置方法.
I think though that the correct approach here comes down to opinion and which method you prefer - I would predict that half the community would agree with the annotations approach and the other half would agree with the external configuration approach.
这篇关于反对注解的论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:反对注解的论点
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01