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.
Advertisement
Answer
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