@ServiceId("Service3") public class Service3 implements IService3 { private final IService2 service2; public Service3(IService2 service2) { this.service2 = service2; } public String generateString() { return service2.generateQuickBrownFox(); } }
/** * Extracts the service id from the passed annotated element. First the {@link ServiceId} annotation is checked. * If present, its value is returned. Otherwise {@link Named} annotation is checked. If present, its value is * returned. * If neither of the annotations is present, <code>null</code> value is returned * * @param annotated * annotated element to get annotations from * @since 5.3 */ public static String getServiceId(AnnotatedElement annotated) { ServiceId serviceIdAnnotation = annotated.getAnnotation(ServiceId.class); if (serviceIdAnnotation != null) { return serviceIdAnnotation.value(); } Named namedAnnotation = annotated.getAnnotation(Named.class); if (namedAnnotation != null) { String value = namedAnnotation.value(); if (InternalCommonsUtils.isNonBlank(value)) { return value; } } return null; }
/** * Extracts the service id from the passed annotated element. First the {@link ServiceId} annotation is checked. * If present, its value is returned. Otherwise {@link Named} annotation is checked. If present, its value is * returned. * If neither of the annotations is present, <code>null</code> value is returned * * @param annotated * annotated element to get annotations from * @since 5.3 */ public static String getServiceId(AnnotatedElement annotated) { ServiceId serviceIdAnnotation = annotated.getAnnotation(ServiceId.class); if (serviceIdAnnotation != null) { return serviceIdAnnotation.value(); } Named namedAnnotation = annotated.getAnnotation(Named.class); if (namedAnnotation != null) { String value = namedAnnotation.value(); if (InternalCommonsUtils.isNonBlank(value)) { return value; } } return null; }
@ServiceId("BarneyService") public class ServiceIdViaAnnotationServiceImpl implements Runnable { @Override public void run() { } }
@ServiceId("FooService") public static Runnable buildSomething() { return new ServiceIdViaMethodAnnotationServiceImpl(); }