I have a very simple REST application that exposes a single @GET endpoint. I am able to run jersey and return a string or JSON object just fine. However, I am unable to connect this with my persistence layer. How can I possibly inject by DataSource instance object into every Resource instantiated by Jersey?
Yes, yes I've seen the dozens of answers with either Guice or other InjectionProviders, etc. but I refuse to believe that I can't pass a reference without writing hundreds of lines of unnecessary code.
I tried using something like in the Rest Server :
final ResourceConfig rc = new ResourceConfig().packages(RestPathPing.class.getPackage().getName());
Map<String, Object> customResourceConfigProps = new HashMap<>();
customResourceConfigProps.put("dataSource", dataSource);
rc.addProperties(customResourceConfigProps);
and then tried getting the ResourceConfig from the @Context but it returns null. I really need a simple short solution since I have the DataSource instance available at Rest server's creation time.