java-21slack-bolt

Slack bolt's compatibility with Java 21


I'm working with a new project based on Java 21 that uses the latest bolt version "1.39.3" for dependencies com.slack.api:bolt, com.slack.api:bolt-servlet, com.slack.api:bolt-socket-mode.

I am getting the following stacktrace

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'slackApp' defined in class path resource [com/rakuten/microservice/infra/configuration/SlackAppConfiguration.class]: Failed to instantiate [com.slack.api.bolt.App]: Factory method 'slackApp' threw exception with message: javax/websocket/DeploymentException
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
    at com.rakuten.microservice.MicroserviceApplication.main(MicroserviceApplication.java:10)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.slack.api.bolt.App]: Factory method 'slackApp' threw exception with message: javax/websocket/DeploymentException
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
    ... 22 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/websocket/DeploymentException
    at com.slack.api.Slack.socketMode(Slack.java:174)
    at com.slack.api.bolt.socket_mode.SocketModeApp.lambda$buildSocketModeClientFactory$2(SocketModeApp.java:76)
    at com.slack.api.bolt.socket_mode.SocketModeApp.run(SocketModeApp.java:187)
    at com.slack.api.bolt.socket_mode.SocketModeApp.start(SocketModeApp.java:177)
    at com.rakuten.microservice.infra.configuration.SlackAppConfiguration.slackApp(SlackAppConfiguration.java:22)
    at com.rakuten.microservice.infra.configuration.SlackAppConfiguration$$SpringCGLIB$$0.CGLIB$slackApp$0(<generated>)
    at com.rakuten.microservice.infra.configuration.SlackAppConfiguration$$SpringCGLIB$$FastClass$$1.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:339)
    at com.rakuten.microservice.infra.configuration.SlackAppConfiguration$$SpringCGLIB$$0.slackApp(<generated>)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140)
    ... 23 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.websocket.DeploymentException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    ... 36 common frames omitted

So this looks like Bolt is looking for javax classes, and is therefore not compatible with Java 21 (which has the jakarta namespace).

Is my understanding correct? How do I work with Bolt and Java 21?


Solution

  • Following their official documentation with references to Example apps with Spring Boot and further its sample code for spring-boot-3 under the build.gradle. I could figure it out and verify that the dependency that you need(sharing Maven construct) would be:

    <dependency>
        <groupId>com.slack.api</groupId>
        <artifactId>bolt-jakarta-servlet</artifactId>
        <version>1.39.3</version>
    </dependency>
    

    Quoting further from the bolt-socket-mode, the dependencies required would be:

    <dependency>
      <groupId>com.slack.api</groupId>
      <artifactId>bolt</artifactId>
      <version>1.39.3</version>
    </dependency>
    <dependency>
      <groupId>com.slack.api</groupId>
      <artifactId>bolt-socket-mode</artifactId>
      <version>1.39.3</version>
    </dependency>
    <dependency>
      <groupId>javax.websocket</groupId>
      <artifactId>javax.websocket-api</artifactId>
      <version>1.1</version> <!-- this should help you-->
    </dependency>
    <dependency>
      <groupId>org.glassfish.tyrus.bundles</groupId>
      <artifactId>tyrus-standalone-client</artifactId>
      <version>1.19</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.36</version>
    </dependency>