@Optional resource not being injected [message #1062384] |
Fri, 07 June 2013 09:20  |
Eclipse User |
|
|
|
Dear All,
I have a resource declared as @Creatable @Singleton.
The resource is properly injected if I use @Inject.
If I use @Inject @Optional the resource is not injected.
Any clues as to what may be wrong?
Thanks in advance and cheers,
Zac
-- sw versions
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.3.el6_3.1-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
Eclipse for RCP and RAP Developers
Version: Juno Service Release 2
Build id: 20130225-0426
|
|
|
|
Re: @Optional resource not being injected [message #1062933 is a reply to message #1062622] |
Tue, 11 June 2013 09:07   |
Eclipse User |
|
|
|
hi Dirk,
Here is the documentation for "@Optional" which I rely on:
"
The @Optional annotation can be applied to methods, fields, and parameters to mark them as optional for the dependency injection. Typically, if the injector is unable to find a value to inject, then injection will fail. However, if this annotation is specified, then:
for parameters: a null value will be injected;
for methods: the method calls will be skipped;
for fields: the values will not be injected.
"
which means that a method annotated with @Optional will be skipped not executed regardless of its existence in the context.
But in any case; I have a field annotated with @Optional and the problem is that the resource *is* available because I can inject it in a view from the same application context.
The reason I annotate this resource with @Optional is because this piece of code can execute in different applications, some of them have the resource in question but others do not have it.
I thought that @Optional was meant for this scenario...
Is there a chance this is a bug in RCP Juno?
I'll try the beta kepler later and see if that works.
Thanks for the message.
Cheers,
Zac
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.76318 seconds