how to replace @properties annotation in aem 6.4 using OSGi R6 annotations

Avatar

Avatar

swati_kad

Avatar

swati_kad

swati_kad

10-10-2018

import org.apache.felix.scr.annotations.Component;

import org.apache.felix.scr.annotations.Properties;

import org.apache.felix.scr.annotations.Property;

import org.apache.felix.scr.annotations.Reference;

import org.apache.felix.scr.annotations.Service

@Component(label="Myproject Service")

@Properties({

@Property(name = Constants.SERVICE_RANKING, intValue = 400, propertyPrivate = true),

@Property(name = "priority", intValue = 200)

})

@Service({Myservice.class})

The felix scr annotations in aem 6.2 is now replaced with OSGi R6 annotations. But  how to replace it ?

I have tried one method. Please do let me know is it correct and how to use "properties" in OSGI R6.

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

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

import org.osgi.service.metatype.annotations.AttributeDefinition;

import org.osgi.service.metatype.annotations.ObjectClassDefinition;

@Component(service=Myservice.class,immediate = true,name="Myproject Service",

property = {"Constants.SERVICE_RANKING="+"400","priority="+"200"  })

Is this correct ?

and how to use properties label in OSGi R6 ?

Accepted Solutions (1)

Accepted Solutions (1)

Answers (9)

Answers (9)

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

11-10-2018

Excellent community input everyone!

Avatar

Avatar

raj_mandalapu

MVP

Avatar

raj_mandalapu

MVP

raj_mandalapu
MVP

11-10-2018

Yes,  you need to declare new variables on top of it add AttributeDefinitions and you need to same variables name which were defined earlier

Avatar

Avatar

swati_kad

Avatar

swati_kad

swati_kad

11-10-2018

But for this I have to declare the new variable ? isn't it ?

Avatar

Avatar

raj_mandalapu

MVP

Avatar

raj_mandalapu

MVP

raj_mandalapu
MVP

11-10-2018

You can use OCD Attribute definitions to convert this into OSGI

EX :

@AttributeDefinition(name = "Constants.SERVICE_DESCRIPTION", description = "Content Insights Page Name Resolver implementation")

String getDescription();

https://blog.osoco.de/2015/11/osgi-components-simply-simple-part-iii/

http://keysandstrokes.info/aem-code-snippets-osgi-annotations/

You need to follow below apprach if you want to convert as it is something like adding Prorperty = { key=value,key=value }

Ex :

@Component(metatype = true, immediate = true, label = "Content Insights Page Name Provider", description = "Service to use custom content insights page name variable")

, Property = { Constants.SERVICE_DESCRIPTION  = "Content Insights Page Name Resolver implementation",

Constants.SERVICE_RANKING, intValue = 200, propertyPrivate = false }

@AttributeDefinition(name = "Feed Url", description = "Feed Url")
String feedUrl();

Avatar

Avatar

Shashi_Mulugu

MVP

Avatar

Shashi_Mulugu

MVP

Shashi_Mulugu
MVP

11-10-2018

You need to declare Object Class Definitions(OCD).

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

Avatar

Avatar

swati_kad

Avatar

swati_kad

swati_kad

11-10-2018

Thanks @arun patidar

@Service

@Component(metatype = true, immediate = true, label = "Content Insights Page Name Provider", description = "Service to use custom content insights page name variable")

@Properties({

@Property(name = Constants.SERVICE_DESCRIPTION, value = "Content Insights Page Name Resolver implementation"),

@Property(name = Constants.SERVICE_RANKING, intValue = 200, propertyPrivate = false),

@Property(name = "basePath", value = "/content/myproject/language-masters/en", description="The path to be removed from Content Insights URL", label="basePath"),

@Property(name = "blogBasePath", value = "/content/myproject-blog/en", description="The path to be removed from Content Insights URL for Blogs", label="blogBasePath"),

@Property(name = "cqVarContentInsight", value = "pagedata.path", description="The CQ variable used for Content Insights URL", label="cqVarContentInsight"),

@Property(name = "langBasePath", value = "/content/myproject/language-masters", description="The path to be removed from Content Insights URL", label="langBasePath")})

Could you please help me in this ?

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

857

Avatar

Arun_Patidar

MVP

Total Posts

3.0K

Likes

1.1K

Correct Reply

857
Arun_Patidar
MVP

10-10-2018

Hi,

YOU can do like below:

No need to put properties in quotes.

@Component(service = MyService.class, immediate = true, property = {

Constants.SERVICE_RANKING + "=400",

"priority=200"

})

Avatar

Avatar

swati_kad

Avatar

swati_kad

swati_kad

10-10-2018

Thanks @Arun patidar

But I have already gone through the documents but it doesn't contain @properties solution.