Hi

I have some points concerning SCA Java Component Implementation
Specification that I'd like to clarify.

1/ use of @Service annotation  (p. 2)
In this document, it is said that a service offered by a component can be
defined in two ways :

a/  by an interface

Diapositive 4 @Service (HelloService.class)
Public class HelloServiceImpl implements HelloService {
 public String hello(String message) {
…
}

HelloService.java (interface) defines the method implemented by the
component in HelloServiceImpl.java

b/  by a class

Diapositive 6 @Service (HelloServiceImpl.class)
Public class HelloServiceImpl implements AnotherInterface {
 public String hello(String message) {
…
}

In this case the java class itself defines the service offered by the
component


*my question : Why to have such a choice ? Is an interface not enough to
define service offered by a component ?*


2/ use of @Reference annotation(p.4)

we can use @Reference in one of the following ways :

a/ with setter method

public class MyClientImpl implements MyClient{

    private MyService myService;

    @Reference
    public void setMyService(MyService myService) {
        this.myService = myService;
    }

 b/ with field  injection

public class MyClientImpl implements MyClient{
  @Reference (name="myService")
  protected MyService myService;
...
}

Diapositive 11where myService is the reference to a service used by MyClient
component

*my question : Why and when to prefer setter method than field injection ?*

3/ References (p.4)

Do we have two distinct manners of obtaining references? One through
injection and one through ComponentContextAPI ?

Thanks
Fahim

Reply via email to