I want to launch DynamoDB Local V2 embedded in a Unit Test.
Here are the important bits from my pom.xml
:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.21.29</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
[...]
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>DynamoDBLocal</artifactId>
<version>2.1.0</version>
<scope>>test</scope>
</dependency>
[...]
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb-enhanced</artifactId>
<exclusions>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
</exclusion>
</exclusions>
</dependency>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>test-compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>test</includeScope>
<includeTypes>so,dll,dylib</includeTypes>
<outputDirectory>${project.basedir}/native-libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Here are the important bits of the JUnit5 Unit Test:
private static DynamoDBProxyServer server;
@BeforeAll
public static void before() throws Exception {
String args[] = {"-inMemory", "-port", "8000"};
DynamoDBProxyServer server = ServerRunner
.createServerFromCommandLineArgs(args);
server.start();
}
@AfterAll
public static void stop() throws Exception {
server.stop();
}
And here's what I'm getting when trying to run it:
java.lang.IllegalAccessError: class com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer tried to access protected method 'void org.eclipse.jetty.server.Handler$AbstractContainer.<init>()' (com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer and org.eclipse.jetty.server.Handler$AbstractContainer are in unnamed module of loader 'app')
at com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer.setUpHandler(DynamoDBProxyServer.java:52)
at com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer.<init>(DynamoDBProxyServer.java:39)
at com.amazonaws.services.dynamodbv2.local.main.ServerRunner.createServer(ServerRunner.java:149)
at com.amazonaws.services.dynamodbv2.local.main.ServerRunner.createServerFromCommandLineArgs(ServerRunner.java:134)
This looks like a Java Module issue. I have not had to debug one of these since Java 8 -> 9 migration many years ago. It's 2023... this shouldn't be happening, is there a simple fix?