可以在JSR 330中将@Inject做为可选项(像@Autowire(required = false)) [英] Can @Inject be made optional in JSR 330 (like @Autowire(required=false)?

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

问题描述

可以配置Spring的 @Atoto ,使得如果没有找到匹配的autowire候选项,Spring不会抛出错误: @Autowire(required = false )



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

解决方案

否...没有等同于可选的JSR 330 ...如果要使用可选注入,那么您将不得不坚持框架特定的 @Autowired 注释


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

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.

解决方案

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

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

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