现在我已经知道了春天的mvc。 完全是关于
context:component-scan
和
mvc:annotation-driven
和
tx:annotation-driven
在spring config xml
中这是我的问题。 据我所知,“context:component-scan”扫描所有bean。 正如我所听到的,mvc:annotation-driven,tx:annotation-driven“s也扫描所有bean。
我认为这不高效且不合理。
为什么要扫描两次,三次。
有没有办法避免这种duicate解析?
任何答案都将不胜感激。 谢谢。
答案 0 :(得分:0)
在我看来,扫描过程不是你想象的两倍,三倍
我认为他们是为相关的豆子申报的
请参考以下总结并了解差异。
<context:annotation-config>
Declares support for general annotations such as @Required, @Autowired, @PostConstruct, and so on.
<context:component-scan>
can also do what <context:annotation-config> does but <context:component-scan> also scans packages to find and register beans within the application context.
<mvc:annotation-driven />
Enables the Spring MVC @Controller programming model and
declares explicit support for annotation-driven MVC controllers (i.e. @RequestMapping, @Controller, although support for those is the default behaviour), as well as adding support for declrative validation via @Valid and message body marshalling with @RequestBody/ResponseBody.
<tx:annotation-driven />
You do provide the transaction-manager instace directly within element. annotation-config and component-scan won't.