I have a question more on the ground on understanding why it is done so.
So I have a servlet in my project on which when I am using @Reference is throws me error "The annotation @Reference is disallowed for this location". But a similar servlet in a new project is not throwing the error. For both of them I am using OSGI annotations. I read that we have to do @Reference in a different way https://www.aemquickstart.in/2018/10/annotation-reference-is-disallowed-for.html . It works . But My question is why are we doing it in that way ? Just want to understand the reasoning and logic and technicalities. Also , why it worked in my new project . Since it worked in one and not in the other , I am bit confused and eager to know what actually controls this
Worked
Didn't work
Thanks
Veena
Solved! Go to Solution.
Views
Replies
Total Likes
Hope this would provide more clues to check the library versions in pom.xml/generated scr:component xmls under OSGI-INF folder --
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
source: Getting Started with OSGi Declarative Services | vogella blog
7.3 @Reference
It is used to specify the dependency on other services. With DS 1.2 it can only be used with Event Methods. DS 1.3 also introduced the usage of @Reference on fields and the type element reference of @Component .
The @Reference annotation needs to be applied on the bind event method. The following defaults are used in that case:
It will infer a default unset method and updated method based on the name of the bind method.
Also introduced with DS 1.3 is the Field Strategy for binding services. With this it is not necessary to specify a bind event method for a reference. Instead it is possible to apply the @Reference annotation to a field in the component implementation class. For a static reference the field will be set before the component instance is activated. Dynamic references need to be marked as volatile so that changes to that field are also visible to other threads.
When applying @Reference on a field, the following defaults are used:
Note: Only instance fields are supported. The @Reference annotation can not be applied to static fields.
source: https://blog.osoco.de/2016/05/migrating-from-the-apache-felix-scr-annotations-to-the-osgi-declarativ...
APACHE FELIX SCR ANNOTATION | DESCRIPTION | OSGI DECLARATIVE SERVICES ANNOTATION | DESCRIPTION |
---|
@Reference | Reference to services, can be used on unary fields or on class level with bind/unbind methods. | @Reference | Field references can directly be migrated, for event based references (methods), the @Reference annotation must be put on the bind method. In addition, more options for field references exist. |
Hi All,
I my case, I removed the below dependency from pom.xml files and it solved the issue.
<dependency> <groupId>biz.aQute</groupId> <artifactId>bndlib</artifactId> </dependency>
Hi All,
I my case, I removed the below dependency from pom.xml files and it solved the issue.
<dependency> <groupId>biz.aQute</groupId> <artifactId>bndlib</artifactId> </dependency>
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies