users@hk2.java.net

ServiceLocator.getService() failing for _at_Service-annotated classes

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Wed, 04 Dec 2013 17:37:32 -0500

Hi,

I've got something along the lines of:

@Service
public class TestClass
{
     @Inject
     public TestClass()
     {
     }
}

public class MyApplication extends ResourceConfig
{
   @Inject
   public MyApplication(ServiceLocator serviceLocator)
   {
     TestClass test = serviceLocator.getService(TestClass.class);
   }
}

but serviceLocator.getService(TestClass.class) returns null. What am I
missing? Isn't HK2 supposed to auto-bind @Service-annotated classes somehow?

PS: Do you monitor the "hk2" tag on Stackoverflow? I think it's a more
efficient way of handling recurring questions.

Thanks,
Gili