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

The attribute reference is undefined for the annotation type Component

sai1007
Level 1
Level 1

Hi,

 

I am not able to find solution for above error. please find my code snippet below

 

 

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;

@component(/* service = ConfigUtil.class, */ immediate = true,

reference = {
@reference(name = "configutil",  bind = "bindAssetDetailsSelector" 
unbind = "unbindAssetDetailsSelector", service = DataPowerUrlUtil.class,
policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE
) }
)

 

using maven-bundle-plugin version 4.2.1,  <artifactId>org.osgi.service.component.annotations</artifactId> verion 1.4.0,

R7 annotation

 

Thanks,

Sai

1 Accepted Solution
kchaurasiya
Correct answer by
Level 6
Level 6

Hi Sai, Just check the below and try.

 

@Component(service =  ConfigUtil.class, configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true)
@Designate(ocd = ConfigUtilImpl.Config.class)

Thanks. 

View solution in original post

4 Replies
kchaurasiya
Correct answer by
Level 6
Level 6

Hi Sai, Just check the below and try.

 

@Component(service =  ConfigUtil.class, configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true)
@Designate(ocd = ConfigUtilImpl.Config.class)

Thanks. 

View solution in original post

Ritesh_M
Community Advisor
Community Advisor
 

Hi @sai1007 ,

 

Which Maven Archetype you are using in your project? I am able to include @Reference annotation inside @Component annotation without any issue. I am using 6+ version of OSGI dependencies. Try using below if it resolves your issue-
(Also, I see there is one comma missing after 'bind = "bindAssetDetailsSelector" ' and small 'r' for Reference annotation but I believe those are just typos.)

 
<!-- OSGi Dependencies -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>6.0.1</version>
<scope>provided</scope>
</dependency>

shelly-goel
Community Advisor
Community Advisor

I think you have to use @OsgiService annotation instead of @reference