Spring框架注解问题 [英] Spring framework annotation question

查看:32
本文介绍了Spring框架注解问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果同时支持XML和annotation,spring框架什么时候做annotation扫描以及如何处理?

In case of supporting both XML and annotation, when spring framework do the annotation scan and how to process it?

谁能给出详细的场景?

对于 XmlWebApplicationContext,它通过 Xml 文件使用 loadBeanDefinations().但是什么时候做注解扫描,用哪个类来处理呢?

For XmlWebApplicationContext, it use loadBeanDefinations() via Xml file. But when it do the annotation scan and use which class to process it?

能详细解释一下吗?

谢谢.

富兰克林

推荐答案

在基于 XML 的应用程序上下文中,注解仅在您明确配置时注册:

In an XML based Application Context, annotations are only registered if you explicitly configure that:

<!-- register default annotations (e.g. @Required) -->
<context:annotation-config />

<!-- scan for components in selected package -->
<context:component-scan base-package="org.example"/>

参考:

如果您想检查内部工作原理,请参阅:

And if you want to check the inner workings, see:

这篇关于Spring框架注解问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆