问题描述
我的团队正在迁移到 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.
这篇关于反对注解的论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)