Exceptions for creating driver in Jersey Application

I am creating a servlet application with Jersey 2.32, running in Tomcat 9.

Jersey provides an Application class and I want to create an instance of a Neo4J connection or driver there, which should be used for all sessions and transactions in the resources.

The main entry point for this servlet looks like this

import java.util.HashSet;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import org.slf4j.LoggerFactory;

import dbConnection.Neo4JConnection;
import restResources.Test;
import restResources.User;

import org.slf4j.Logger;

@ApplicationPath("/")
public class MyMain extends Application {
	
	private final static Logger logger = LoggerFactory.getLogger(MyMain.class);
	
	private Neo4JConnection dbConn;
	
    /**
     * Responsible for collecting the resources for REST endpoints.
     * This method is called twice.
     */
	@Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resourceClasses = new HashSet<Class<?>>();
        resourceClasses.add(Test.class);
        resourceClasses.add(User.class);

        logger.debug("We are in main class, collecting resources. {}", resourceClasses.toString());
        return resourceClasses;
    }
	
	@PostConstruct
	public void initialize() {
		try {
			this.dbConn = new Neo4JConnection("bolt://localhost:7687", "myuser", "mypassword");
		} catch (Exception ex) {
			logger.error("Error while creating Neo4j driver {}, {}", ex.getMessage(), ex);
		}
	}
	
	@PreDestroy
    public void cleanUp() {
		try {
			this.dbConn.close();
		} catch (Exception ex) {
			logger.error("Error on closing Neo4J driver {}", ex.getMessage(), ex);
		}
	}
}

The Connection (actually Driver) class is a simple version of the documented diver usage

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;

/**
 * @author myname
 *
 */
public class Neo4JConnection implements AutoCloseable {

    private final Driver driver;

    public Neo4JConnection( String uri, String user, String password )
    {
        driver = GraphDatabase.driver( uri, AuthTokens.basic( user, password ) );
    }

    @Override
    public void close() throws Exception
    {
        driver.close();
    }
}

pom.xml dependencies:

<dependency>
	<groupId>javax.ws.rs</groupId>
	<artifactId>javax.ws.rs-api</artifactId>
	<version>2.1.1</version>
</dependency>
<dependency>
	<groupId>org.glassfish.jersey.inject</groupId>
	<artifactId>jersey-hk2</artifactId>
	<version>${version.jersey}</version>
</dependency>
<dependency>
	<groupId>org.glassfish.jersey.core</groupId>
	<artifactId>jersey-server</artifactId>
	<version>${version.jersey}</version>
</dependency>
<dependency>
	<groupId>org.glassfish.jersey.containers</groupId>
	<artifactId>jersey-container-servlet</artifactId>
	<version>${version.jersey}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>${version.jersey}</version>
</dependency>
<!-- snip -->
<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>4.2.0</version>
</dependency>

I don't use a resource entry in the context.xml for Tomcat, which is recommended for the neo4j-jdbc-driver.

But I get exceptions on startup:

1. Reflection Problem?

21:19:25.153 [main] DEBUG org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0 - direct buffer constructor: unavailable
java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:238) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:232) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:293) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.newTaskQueue0(NioEventLoop.java:279) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.newTaskQueue(NioEventLoop.java:150) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:138) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:146) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:37) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:52) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:96) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:91) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:72) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:52) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.async.connection.EventLoopGroupFactory$DriverEventLoopGroup.<init>(EventLoopGroupFactory.java:112) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.async.connection.EventLoopGroupFactory.newEventLoopGroup(EventLoopGroupFactory.java:68) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.async.connection.BootstrapFactory.newBootstrap(BootstrapFactory.java:33) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.DriverFactory.createBootstrap(DriverFactory.java:261) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:77) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:67) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:139) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:121) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:96) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at dbConnection.Neo4JConnection.<init>(Neo4JConnection.java:20) ~[classes/:?]
	at sustainableDataPlatform.org.MyMain.initialize(MyMain.java:53) ~[classes/:?]

2. Illegal Access

21:19:25.188 [main] DEBUG org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable
java.lang.IllegalAccessException: class org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @6144e499
	at jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361) ~[?:?]
	at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:558) ~[?:?]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:352) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:343) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:293) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.newTaskQueue0(NioEventLoop.java:279) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.newTaskQueue(NioEventLoop.java:150) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:138) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:146) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:37) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:52) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:96) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:91) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:72) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:52) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.async.connection.EventLoopGroupFactory$DriverEventLoopGroup.<init>(EventLoopGroupFactory.java:112) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.async.connection.EventLoopGroupFactory.newEventLoopGroup(EventLoopGroupFactory.java:68) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.async.connection.BootstrapFactory.newBootstrap(BootstrapFactory.java:33) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.DriverFactory.createBootstrap(DriverFactory.java:261) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:77) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:67) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:139) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:121) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:96) ~[neo4j-java-driver-4.2.0.jar:4.2.0-fc5c117bc4ba08132e393f75bcf9a9419cd1b729]
	at dbConnection.Neo4JConnection.<init>(Neo4JConnection.java:20) ~[classes/:?]
	at sustainableDataPlatform.org.MyMain.initialize(MyMain.java:53) ~[classes/:?]

My questions:

  1. should I use neo4j-jdbc-driver for this setup?
  2. which parts of a config for the driver do I have to use?
  3. Can I avoid the problems by using the driver at a different point of startup? (Problems with PostConstruct vs. Application constructor?
  4. the vaguest one: how can I use the same driver in all resources programatically (is there any tutorial / introduction for this)?

Update for topic

(since I apparently cannot edit it

I am actually getting a Driver. The printed errors are logged on Debug level.

But I'd be interested in the meaning of these exceptions anyway, since to me it seems like they are thrown by the driver library. Is there any way to avoid them?