내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

AEM Services

Avatar

Level 6

Can we use @reference annotation in normal class or can we get osgi services in normal class in aem

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor and Adobe Champion

What do you mean by "normal" class? If you mean plain Java classes POJO (Plain Old Java Object) the simple answer is No.

 

the @reference annotation is part of the OSGi Declarative Services (DS) specification. It is used to inject OSGi services into OSGi component classes, which are typically OSGi service components.

The @reference annotation cannot be used directly in a normal Java class because it is specifically meant for OSGi service components that are registered and managed by the OSGi framework. Normal Java classes are not part of the OSGi service registry, and hence, the @reference annotation is not applicable to them.

 



Esteban Bustamante

원본 게시물의 솔루션 보기

2 답변 개

Avatar

정확한 답변 작성자:
Community Advisor and Adobe Champion

What do you mean by "normal" class? If you mean plain Java classes POJO (Plain Old Java Object) the simple answer is No.

 

the @reference annotation is part of the OSGi Declarative Services (DS) specification. It is used to inject OSGi services into OSGi component classes, which are typically OSGi service components.

The @reference annotation cannot be used directly in a normal Java class because it is specifically meant for OSGi service components that are registered and managed by the OSGi framework. Normal Java classes are not part of the OSGi service registry, and hence, the @reference annotation is not applicable to them.

 



Esteban Bustamante

Avatar

Employee

the @reference annotation can not be used in normal Java classes,you can use the @reference annotation to inject references to other OSGi services into the component class.

 

For example, in a Sling Model class, you can use the @reference annotation to inject an OSGi service

 

import org.osgi.service.component.annotations.Reference;
import org.apache.sling.models.annotations.Model;

@Model(adaptables = Resource.class)
public class MySlingModel {
    @reference
    private MyOsgiService myOsgiService;
    
    // ... Rest of the code ...
}