public interface GreetingService {
void greet(String name);
}
@Service
@Component(name="HelloService", service = GreetingService.class)
public class HelloService implements GreetingService {
@Override
public void greet(String name) {
System.out.println("Hello, " + name + "!");
}
}
@Component
public class MyComponent {
@Reference
private GreetingService greetingService;
public void doSomething() {
greetingService.greet("Alice");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="MyComponent">
<implementation class="com.example.MyComponent"/>
</scr:component>