¿Cómo ServiceLocator encuentra @Service y @Contact automáticamente en HK2?
De acuerdo con HK2@Servicio javadoc
Anotación colocada en clases que seránautomáticamente agregado a un hk2 ServiceLocator.
No se como hacerServiceLocator
Encuentra clases anotadas automáticamente.
TestService
@Contract
public interface TestService {
}
TestServiceImpl
@Service
public class TestServiceImpl implements TestService {
}
Principal
public static void main(String[] args) {
ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator();
TestService service = locator.getService(TestServiceImpl.class);
System.out.println(service); // null
}
El resultado es siemprenull
. Tengo que agregarDescriptor
entonces elServiceLocator
Lo puedo encontrar.
public static void main(String[] args) {
ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator();
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.bind(BuilderHelper.link(TestServiceImpl.class).to(TestService.class).in(Singleton.class).build());
config.commit();
TestService service = locator.getService(TestServiceImpl.class);
System.out.println(service); // TestServiceImpl instance
}
Como dejoServiceLocator
encuentra las clases anotadas automáticamente? ¿Entendí mal algo?