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

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

Mark Solution

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

해결됨

Sling Component versus Service

Avatar

Level 9

Hi All,

I want to know difference between Sling Component and Service.What are the use cases to be considered to use and implement these two features.

Please help me in understanding both of these.

Thanks,

Kishore

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Administrator

Hi

I have found a very good article, covering everything with example:

Link:- http://www.computepatterns.com/76/osgi-component-vs-service-in-aem/

AEM ships with an OSGi container Apache felix that implements Declarative Services (DS) component model. Most of the developers who are new to AEM often gets confused between OSGi components and services.

OSGi Component
If you want the life of your object to be managed by the OSGi container, you should declare it as a component. Using DS annotations, you could make a POJO a OSGi component by annotating it with@Component With this, you will get the ability to start, stop and configure the component using the felix web console.

OSGi Service
OSGi components can be made as OSGi service by marking it with @service annotation. All it mandates is that an interface Services should implement an interface (1 or more). When you mark a component as service, you could refer (call) this service from other osgi components.

OSGi Component Vs Service

  • All objects managed by OSGi container are components. You qualify components as services. This means that all services are components but not vice-versa.
  • Components can refer/call (using container injection  @reference) other services but not components. In other words, a component cannot be injected into another component / service. Only services can be injected into another component.

Go through the examples....

and in the last, 

OSGi Component Use cases
Now, you must be wondering, why you shouldnt be marking every component as service. Yes, you want your objects to be usable outside its body. However, in certain use-cases modeling your object as component (not marking it as service) makes sense. Here are few of them.

  • A server object in your application which listens to a socket.
  • A filter object which intercepts the requests.
  • An object which monitors a resource and report.
  • An objects which pulls data from external system and writes to the repository.

I hope this would be of some help.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

원본 게시물의 솔루션 보기

3 답변 개

Avatar

Level 10

Avatar

Level 10

Hi Kishore,

In addition with that link given by scott, look into  this thread which answers your question.

http://stackoverflow.com/questions/8886430/what-is-the-difference-between-osgi-components-and-servic...

Also, there are so many number of articles which creates custom OSGI bundle(contains components and services) in this link: https://helpx.adobe.com/marketing-cloud/experience-manager.html

Thanks,
Ratna Kumar.

Avatar

정확한 답변 작성자:
Administrator

Hi

I have found a very good article, covering everything with example:

Link:- http://www.computepatterns.com/76/osgi-component-vs-service-in-aem/

AEM ships with an OSGi container Apache felix that implements Declarative Services (DS) component model. Most of the developers who are new to AEM often gets confused between OSGi components and services.

OSGi Component
If you want the life of your object to be managed by the OSGi container, you should declare it as a component. Using DS annotations, you could make a POJO a OSGi component by annotating it with@Component With this, you will get the ability to start, stop and configure the component using the felix web console.

OSGi Service
OSGi components can be made as OSGi service by marking it with @service annotation. All it mandates is that an interface Services should implement an interface (1 or more). When you mark a component as service, you could refer (call) this service from other osgi components.

OSGi Component Vs Service

  • All objects managed by OSGi container are components. You qualify components as services. This means that all services are components but not vice-versa.
  • Components can refer/call (using container injection  @reference) other services but not components. In other words, a component cannot be injected into another component / service. Only services can be injected into another component.

Go through the examples....

and in the last, 

OSGi Component Use cases
Now, you must be wondering, why you shouldnt be marking every component as service. Yes, you want your objects to be usable outside its body. However, in certain use-cases modeling your object as component (not marking it as service) makes sense. Here are few of them.

  • A server object in your application which listens to a socket.
  • A filter object which intercepts the requests.
  • An object which monitors a resource and report.
  • An objects which pulls data from external system and writes to the repository.

I hope this would be of some help.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni