Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Migration of SCR annotations to OSGi R6 annotations in AEM 6.3

rahuld77778584
Level 2
Level 2

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 { }

1 Accepted Solution
bsloki
Correct answer by
Community Advisor
Community Advisor

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.

View solution in original post

8 Replies
smacdonald2008
Level 10
Level 10

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
Community Advisor
Community Advisor

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.

rahuld77778584
Level 2
Level 2

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
Level 10

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 DataSource...

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

Hope this helps.... 

rahuld77778584
Level 2
Level 2

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
Level 10

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-declarativ...

It talks migrating from SRC annotations to R6.

Looks like @References is not supported in R6.

bsloki
Correct answer by
Community Advisor
Community Advisor

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.

View solution in original post