Apache Felix 中的@Service 注解是什么?
What is the @Service annotation in Apache Felix?
我读过几篇关于 @Service
和 @Component
之间区别的文章。现在我明白 @Component
是用户将对象注释为 OSGi 组件,然后它的生命周期将由 OSGi 管理。
然而,将一个对象声明为带有 @Service
的服务的必要性是未知的。如果您在声明为组件的对象中编写业务逻辑会怎样?
我也想知道下面的语句是什么意思:
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.
问题 1:
What is the @Service annotation in Apache Felix?
The @Service annotation defines whether and which service interfaces
are provided by the component.
你应该明白这是关于OSGi服务的概念,而不是@Component
描述的声明式服务(DS)概念。
避免使用 Felix SCR(包 org.apache.felix.scr.annotations
)中的 注释。
http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html :
The annotations itself do not support the new features from R6 or
above. It is suggested to use the official OSGi annotations for
Declarative Services instead.
使用包 org.osgi.service.component.annotations
中的 @Component
,此注释替换了 Felix 中的 @Component
和 @Service
。
问题 2
What happens if you write your business logic in
a object that is declared as a component?
碰巧工作正常。
问题 3
I also want to know what does the below statement means:
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 there.
这就是组件在 OSGi 中共享功能的方式。它们以 OSGi 服务的形式提供它们的功能。但是当 OSGi 将对象注入到引用中时,您将获得您的组件。
奖励:阅读这篇文章:https://medium.com/adobetech/using-the-osgi-declarative-service-in-aem-6-4-21102f649d54
我读过几篇关于 @Service
和 @Component
之间区别的文章。现在我明白 @Component
是用户将对象注释为 OSGi 组件,然后它的生命周期将由 OSGi 管理。
然而,将一个对象声明为带有 @Service
的服务的必要性是未知的。如果您在声明为组件的对象中编写业务逻辑会怎样?
我也想知道下面的语句是什么意思:
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.
问题 1:
What is the @Service annotation in Apache Felix?
The @Service annotation defines whether and which service interfaces are provided by the component.
你应该明白这是关于OSGi服务的概念,而不是
@Component
描述的声明式服务(DS)概念。
避免使用 Felix SCR(包 org.apache.felix.scr.annotations
)中的 注释。
http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html :
The annotations itself do not support the new features from R6 or above. It is suggested to use the official OSGi annotations for Declarative Services instead.
使用包 org.osgi.service.component.annotations
中的 @Component
,此注释替换了 Felix 中的 @Component
和 @Service
。
问题 2
What happens if you write your business logic in a object that is declared as a component?
碰巧工作正常。
问题 3
I also want to know what does the below statement means:
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 there.
这就是组件在 OSGi 中共享功能的方式。它们以 OSGi 服务的形式提供它们的功能。但是当 OSGi 将对象注入到引用中时,您将获得您的组件。
奖励:阅读这篇文章:https://medium.com/adobetech/using-the-osgi-declarative-service-in-aem-6-4-21102f649d54