Spring MVC 主要使用注释来配置其 Controller ,据我所知,在 Spring 中配置 Controller 而无需注释(仅 XML)的唯一方法是扩展 AbstracController(或类似的 Controller 类),目前所有此类都是Spring 3 已弃用。
虽然我认为放弃对此类的支持是个好主意,主要是因为扩展此类会创建几乎不依赖 Spring 作为依赖项的 Controller ,但我不明白为什么 Spring 不提供像 Struts Actions 这样的配置(Struts 2 中的操作不会扩展任何奇怪的类,因此它们不具有 Struts 的任何依赖性)
为什么 Spring MVC 不提供像 Struts 2 Actions via XML 这样干净的 POJO 样式配置?
为什么要使用丑陋的注释来放弃对 MVC 上 XML 配置的支持?为什么不把它放到所有 Spring 项目中呢?
最佳答案
XML/POJO 方法的主要问题是,无法通过查看代码来判断是否正在发生特殊的魔法。
而不是看到
@SomeAnnotation <<-- Oh, golly there is something special happening here.
java code...
你看
Java code <<-- special magic hidden in XML file (or not, no way to tell)
<<-- are these linked? no idea..
<<-- is something going on? let me go and search....
如果源代码发生更改,XML 可能(也可能不会)不同步。
通过注解,您可以同时更新java代码和spring注解。
是的,它很困惑,但至少很容易同步两者。
当注释出现在您面前时,它们很难理解。如果它们甚至不可见,那么对于我们这些不愤怒的开发者来说,精神负担确实难以承受。
why not to drop it in ALL Spring Projects?
这不是很甜蜜吗......
using ugly Annotations?
显然已经提出了这个问题:Is there a way to hide annotations in Eclipse?
答案是:https://stackoverflow.com/a/2569646/650492
有点……这有帮助吗?
关于java - 为什么 Spring MVC 对 XML 配置的配置支持已被弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19286085/