We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Autowire
@Resource
注意:如果 name 属性一旦指定,就只会按照名称进行装配。
@Qualifier
@Autowired(required = false) @Qualifier("example") private Example example; @Resource(name = "example") private Example example;
@Resouce
链接:https://blog.csdn.net/u012102104/article/details/79481007
The text was updated successfully, but these errors were encountered:
No branches or pull requests
对比
@Autowire
和@Resource
@Autowire
和@Resource
都可以用来装配bean,都可以用于字段或setter方法。@Autowire
默认按类型装配,默认情况下必须要求依赖对象必须存在,如果要允许 null 值,可以设置它的 required 属性为 false。@Resource
默认按名称装配,当找不到与名称匹配的 bean 时才按照类型进行装配。名称可以通过 name 属性指定,如果没有指定 name 属性,当注解写在字段上时,默认取字段名,当注解写在 setter 方法上时,默认取属性名进行装配。@Autowire
和@Qualifier
配合使用效果和@Resource
一样:@Resouce
装配顺序简要对比表格
@Resource
@Autowire
链接:https://blog.csdn.net/u012102104/article/details/79481007
The text was updated successfully, but these errors were encountered: