0

I have a custom annotation:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
public @interface Route {
    String module();
}

One class is annotated with this @interface.

@Route(module="cache")
public class Cache implements ICache {
    ...
}

In my blueprint, I expose this class as a service, exporting all its interfaces.

<service id="cache" auto-export="interfaces">
    <bean class="mypackage.Cache" />
</service>

But when I run this on Karaf, I only see my service as ICache.

Can custom annotation interface be used to export service or do I have to create a standard interface like Interface Route {}?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
jhamon
  • 3,603
  • 4
  • 26
  • 37
  • What are you trying to achieve? Your Cache class only implements `ICache` so only the methods of `ICache` would be available to consumers. If you provided your component as a service of type `Route` then consumers would try to call the `module()` method, and this would break because you don't implement `Route` but are merely annotated with it. – Neil Bartlett May 31 '16 at 10:13
  • I have a TCP server that receives commands in the format `route/method`. What I want to do is find the correct service (the one where `module == route` in order to execute a method that would be also annotated with the correct `method` argument. I want to be able to add service on the fly, so I though using a reference-list on the `Route`interface. Then Reflections do the trick to get the right method – jhamon May 31 '16 at 12:19
  • So this sounds like a job for service properties. – Neil Bartlett May 31 '16 at 12:22
  • Yes, that what I though. I get what I wanted to achieve by implementing a `Route`interface in my `Cache` class and passing my `module` attribute as a service property – jhamon Jun 02 '16 at 07:44

0 Answers0