Hi,

First some context: I'm working on a custom Minecraft server (Spigot)
plugin. It's just a JAR that you export and place somewhere in the server's
folder structure.

I wrote a simple insert query via Cayenne's API. It works when I run the
example JAR directly via executing Main from the command line (java -cp
myPlugin.jar path.to.Main), but it fails with the following error when
executed by the server in my plugin's OnEnable lifecycle hook:

org.apache.cayenne.di.DIRuntimeException: DI container has no binding for
key <BindingKey: org.apache.cayenne.configuration.ObjectContextFactory>


My initial theory was that it's being executed from a different thread, so
the DI system might not have access to that dependency for some reason, but
it seems like the server executes this lifecycle hook from the main thread
as well (though they've named the thread "Server thread", and I don't know
how to check if it's the main thread for sure). Not sure if this is a
promising direction to pursue, but I got the hunch by looking at the
threadInjector bits of Cayenne's DI container docs.

My example looks like this:

ServerRuntime cayenneRuntime = ServerRuntime.builder()
                .addConfig("cayenne-project.xml")
                .build();ObjectContext ctx = cayenneRuntime.newContext();
PlayerConnectionEvent newEvent =
ctx.newObject(PlayerConnectionEvent.class);
newEvent.setEventType(eType);
newEvent.setPlayerName(playerName);
newEvent.setIpAddress(ipAddress);
newEvent.setTimestampUnixSeconds(unixSeconds);

ctx.commitChanges();

Some help would be greatly appreciated, thanks in advance!
-- 
S poštovanjem,
*Stefan Stegić*

Reply via email to