>>>>> Steinar Bang <[email protected]>: > The service definition is > > https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.api/src/main/java/no/priv/bang/ukelonn/UkelonnService.java#L36
> The service implementation, is this DS component > > https://github.com/steinarb/ukelonn/blob/5ca75f438407c594ed476bed790d984b0007cfdf/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnServiceProvider.java#L42 > However, with Jersey getting injection of the above service into the > resource classes isn't so easy. Based in the following two stackoverflow threads I have a tentative plan for getting the service injected into Jersey resources using my current stack (ie. karaf 4.1.5 and OSGi 6.0.0): https://stackoverflow.com/questions/38373867/inject-dao-instance-into-jersey-resource?noredirect=1&lq=1 https://stackoverflow.com/questions/16216759/dependency-injection-with-jersey-2-0 (However, once I'm on karaf 4.2.x and OSGi 7.0.0, and once I hear rumours that Scott Lewis' approach will be working with the http whiteboard, then ditching my resource classes and annotating the service is something I will try) Outline of my plan: 1. Make the service implementation extend ResourcesConfig 2. Create a class extending AbstractBinder, that in its configure() method will bind an instance of the service implmentation to the UkelonnService interface 3. In the @Activate method of the service implementation, register the activated instance with Jersey, using the AbstractBinder above 4. In the resource classes use JSR330 @Inject of the UkelonnService 5. Create a whiteboard DS service from the JerseyServletContainer, with: a. param configuration configuring a package to scan for resources b. add a @Reference for an UkelonnService and an @Activate method, to ensure that the servlet isn't activated, and plugged into the whiteboard until a service is available that can be injected into the created resources (and it should also ensure the servlet is taken down if the UkelonnService implementation is taken down)
