@Inject 可以在 JSR 330 中成为可选的吗(比如 @Autowire(required=false))? [英] Can @Inject be made optional in JSR 330 (like @Autowire(required=false)?

查看:24
本文介绍了@Inject 可以在 JSR 330 中成为可选的吗(比如 @Autowire(required=false))?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring 的 @Autowire 可以配置为如果没有找到匹配的自动装配候选者,Spring 不会抛出错误:@Autowire(required=false)

Spring's @Autowire can be configured such that Spring will not throw an error if no matching autowire candidates are found: @Autowire(required=false)

是否有等效的 JSR-330 注释?如果没有匹配的候选人,@Inject 总是失败.有什么办法可以使用 @Inject 但如果没有找到匹配的类型,框架不会失败?我还没有找到任何相关的文档.

Is there an equivalent JSR-330 annotation? @Inject always fails if there is no matching candidate. Is there any way I can use @Inject but not have the framework fail if no matching types are found? I haven't been able to find any documentation to that extent.

推荐答案

不... JSR 330 中没有与 optional 等效的...@Autowired 注释

No... there is no equivalent for optional in JSR 330... if you want to use optional injection then you will have to stick with the framework specific @Autowired annotation

这篇关于@Inject 可以在 JSR 330 中成为可选的吗(比如 @Autowire(required=false))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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