Created
January 9, 2015 13:34
-
-
Save jliuhtonen/58f0288a6f8712a4905b to your computer and use it in GitHub Desktop.
Add classes to Jersey 2 HK2 injector with reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of registering javax.injection annotated classes to Jersey 2's HK2 instance ServiceLocator | |
// Uses https://code.google.com/p/reflections/ | |
public class RestApplication extends ResourceConfig { | |
@Inject | |
public RestApplication(ServiceLocator serviceLocator) { | |
packages("rest.resource"); | |
ServiceLocatorUtilities.addClasses(serviceLocator, findServiceSingletons()); | |
} | |
private Class[] findServiceSingletons() { | |
Reflections reflections = new Reflections("rest.service"); | |
Set<Class<?>> clazzez = reflections.getTypesAnnotatedWith(Singleton.class); //or other qualifiers | |
return clazzez.toArray(new Class[clazzez.size()]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment