Migration of SCR annotations to OSGi R6 annotations in AEM 6.3 | Community
Skip to main content
rahuld77778584
Level 2
January 23, 2019
Solved

Migration of SCR annotations to OSGi R6 annotations in AEM 6.3

  • January 23, 2019
  • 8 replies
  • 9821 views

I am migrating some SCR annotations based code base to OSGi R6.

The current code uses scr annotations and fields which are not available in R6.

For example: @references  and referenceInterface are not supported in R6

@Component

@References({

  @Reference(

  referenceInterface = SomeFactory.class,

  policy = ReferencePolicy.DYNAMIC,

  cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE)

})

@Service

public class SomeResolverImpl implements SomeResolver { }

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Lokesh_Shivalingaiah

Hi Rahul,

We dont have @References with r6. Also, @Reference interface doesnt support  'referenceInterace' anymore (Refer this - https://osgi.org/javadoc/r6/residential/org/osgi/service/component/annotations/Reference.html )

You may have to declare individual references within the class or if you are looking at referring interface, then you may also see if @Designate annotation works.

8 replies

smacdonald2008
Level 10
January 23, 2019

The best way to proceed here is to rebuild your project using Maven 12 Archetype. This project uses R6 annotations by default.

Creating an Adobe Experience Manager 6.3 Project using Adobe Maven Archetype 12

Notice in this article the use of 6.3 UBER JAR.

Ratna_Kumar
Level 10
January 23, 2019

Hi Rahul,

As Scott stated, the best way to learn how to use R6 annotations from the article: Creating an Adobe Experience Manager 6.3 Project using Adobe Maven Archetype 12

Make sure you include Uber Jar in POM xml file.

Thanks,

Ratna Kumar.

smacdonald2008
Level 10
January 23, 2019
rahuld77778584
Level 2
January 23, 2019

smacdonald2008 Ratna Kumar

Thanks for the reply. I have already checked articles you guys suggested.

However, I am not able to find suitable annotations and field which were available in scr.

Can you answer my specific question?

@references  and referenceInterface are not supported in R6. How do I re implement it in R6?

smacdonald2008
Level 10
January 23, 2019

In R6 - you can use @Reference. The fully qualified package is

//DS Annotations

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.Reference;

This works the same way - it injects an AEM Service. That way, you can use a service like DataSourcePool:

   

    @Reference

    private DataSourcePool source;

               

The other one you mention not in R6.

https://osgi.org/javadoc/r4v43/cmpn/org/osgi/service/component/annotations/package-summary.html

To see a step by step articel that uses @Reference - see this AEM 6.4 one that uses DataSourcePool

Adobe Experience Manager Help | Querying MySQL data using an Adobe Experience Manager 6.4 DataSourcePool

In fact - most of our AEM 6.4 articles use R6 annotations.

Hope this helps.... 

rahuld77778584
Level 2
January 23, 2019

If you see my example, I need to use @reference at class level. (Which was possible in SCR)

I am able to use it at field level i.e. injecting OSGi service using @reference on a field.

smacdonald2008
Level 10
January 23, 2019

Read here too - talks about @Refenence:

Using OSGi R6 annotations (>= AEM6.2) - Experience Delivers

Here is a good piece of information that should help you --

https://blog.osoco.de/2016/05/migrating-from-the-apache-felix-scr-annotations-to-the-osgi-declarative-services-annotatio…

It talks migrating from SRC annotations to R6.

Looks like @References is not supported in R6.

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
January 23, 2019

Hi Rahul,

We dont have @References with r6. Also, @Reference interface doesnt support  'referenceInterace' anymore (Refer this - https://osgi.org/javadoc/r6/residential/org/osgi/service/component/annotations/Reference.html )

You may have to declare individual references within the class or if you are looking at referring interface, then you may also see if @Designate annotation works.