On Sun, Apr 7, 2019 at 4:03 AM Christopher Dodunski < chrisfromtapes...@christopher.net.nz> wrote:
> Hi team, > Hello! > The slight hiccup is that this server endpoint (service) depends on > another service, which I've tried injecting into a field of the endpoint > class: > > @InjectService("VesselStateTracker") > Why not just @Inject? Do you have more than one service implementing VesselStateTracker? > private VesselStateTracker vesselStateTracker; > > The problem is that when Tomcat invokes this endpoint class, the injected > service is not instantiated (makes sense, as Tapestry is configured to > ignore calls to the endpoint). So a null pointer exception occurs as soon > as the endpoint tries to use 'vesselStateTracker' internally. I'm afraid you're wrong about why the problem is happening. Tapestry-IoC is the one actually taking care of services and it knows nothing about ignored paths, which are a Tapestry(-core, the webapp) thing. The problem is that your endpoint doesn't seem to be a Tapestry-IoC service itself, so it doesn't get any dependency injection done to it. > In AppModule I've tried eagerly loading both services after binding them, > and making the VesselStateTracker field a static field inside the > endpoint, but this wasn't successful. > > Is there a simple solution or work-around to this almost expected problem? > I'd try, in your endpoint, to get the Tapestry-IoC registry object from the ServletContext using the TapestryFilter.REGISTRY_CONTEXT_NAME (org.apache.tapestry5.application-registry) key, then call registry.getService(VesselStateTracker.class) on it. > > Thanks & regards, > > Chris. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Thiago