Why use @Component annotation with each service in CQ

后端 未结 2 1614
逝去的感伤
逝去的感伤 2021-02-08 10:35

I am bit confused about following things. I understand @Service and @Component annotations are main annotations when we define a component or a service

2条回答
  •  不要未来只要你来
    2021-02-08 10:52

    • OSGi is the one where bundles are installed and manages. Everything that needs to be there in OSGi has to be a component be it simple component, a service or servlet. That is why we need to use @Component with service also.

    • Services are singleton. Everything that needs to be managed for Singleton class and using reference of service is done by OSGi. Nothing has to be done from our side. So everything is automatically managed.

    • You dont access components like that. Components are independently used. Quoting example from different post: Suppose you want to a write Server component that sits on socket and responds to requests over TCP/IP. When the component starts, it opens the socket and creates the thread(s) required to serve clients. When it stops, it closes the thread(s) and socket

提交回复
热议问题