英文:
Spring Boot Redis error when dockerized, but not with maven run
问题
我正在使用Spring Boot和Redis(使用redisson)构建一个应用程序。
当我在开发模式下运行应用程序时,它正常工作,但是当我尝试在Docker容器中运行它时,它出现以下错误:
java.lang.ClassNotFoundException: org.springframework.data.redis.connection.ReactiveStreamCommands
我的Redis的Maven配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<!-- for Spring Data Redis v.2.2.x -->
<artifactId>redisson-spring-data-22</artifactId>
<version>3.12.2</version>
</dependency>
用于构建Docker容器的Maven配置:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.1</version>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
<imageName>${imageName}</imageName>
<!-- 默认用于标记镜像的属性 -->
<image>${imageName}</image>
<newName>${imageName}:${tagName}</newName>
<!-- gitlab registry -->
<serverId>gitlab-repository</serverId>
<registryUrl>my.repository</registryUrl>
<baseImage>adoptopenjdk/openjdk11-openj9:latest</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- 将服务的jar文件从target复制到镜像的根目录 -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
当我登录到容器并分析我的jar库(使用以下命令):
jar -tf my-app.jar | grep redis
我发现了以下内容:
BOOT-INF/lib/spring-boot-starter-data-redis-2.1.3.RELEASE.jar
BOOT-INF/lib/spring-data-redis-2.1.5.RELEASE.jar
BOOT-INF/lib/redisson-spring-data-22-3.12.2.jar
BOOT-INF/lib/redisson-3.12.2.jar
这与我在开发环境中得到的完全相同。
以下是我在docker-compose中如何启动Redis的摘录:
redis:
image: redis:5.0
ports:
- 6379:6379
networks:
- network
volumes:
- redis:/data
entrypoint: redis-server --appendonly yes
restart: unless-stopped
有关容器正常运行所缺少的内容有什么线索吗?
为什么在jar中使用的spring-data-redis版本是2.1.5而不是2.2.x?
提前谢谢您的回答。
英文:
I am building an application with Spring Boot using Redis (with redisson).
When I run my application in development mode, it works fine, but when I try to run it in docker containers, it fails with the error
java.lang.ClassNotFoundException:org.springframework.data.redis.connection.ReactiveStreamCommands
My maven configuration for Redis :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<!-- for Spring Data Redis v.2.2.x -->
<artifactId>redisson-spring-data-22</artifactId>
<version>3.12.2</version>
</dependency>
My maven configuration to build docker container :
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.1</version>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
<imageName>${imageName}</imageName>
<!-- default properties to tag an image -->
<image>${imageName}</image>
<newName>${imageName}:${tagName}</newName>
<!-- gitlab registry -->
<serverId>gitlab-repository</serverId>
<registryUrl>my.repository</registryUrl>
<baseImage>adoptopenjdk/openjdk11-openj9:latest</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory
of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
When I login to my container and analysie my jar libraries (with the following command):
jar -tf my-app.jar | grep redis
I find this :
BOOT-INF/lib/spring-boot-starter-data-redis-2.1.3.RELEASE.jar
BOOT-INF/lib/spring-data-redis-2.1.5.RELEASE.jar
BOOT-INF/lib/redisson-spring-data-22-3.12.2.jar
BOOT-INF/lib/redisson-3.12.2.jar
Which is exactly the same as I get with my jar for development.
Here is the docker-compose extract on how I launch redis :
redis:
image: redis:5.0
ports:
- 6379:6379
networks:
- network
volumes:
- redis:/data
entrypoint: redis-server --appendonly yes
restart: unless-stopped
Any clue on what is missing for my container to run properly?
Any idea why the spring-data-redis used in the jar is 2.1.5 and not 2.2.x ?
Thanks in advance
答案1
得分: 0
我已经找到了一个解决方案:
我不再使用 redisson-spring-data-22
,而是降级为 redisson-spring-data-16
(因为我注意到实际使用的 spring-data-redis 版本实际上是 2.1.5,低于 2.2 ...)。
我不能真正解释为什么,但是现在它可以工作了。
我在 redisson-spring-data 上找不到关于在什么条件下应该使用哪个版本的任何信息,所以我只是尝试了另一个版本... 然后它就可以工作了!
希望对你有所帮助。
英文:
I have found a solution :
Instead of using redisson-spring-data-22
, I downgraded to redisson-spring-data-16
(as I noticed that the effective version of spring-data-redis used was in fact 2.1.5, which is lower than 2.2 ...).
I cannot explain why really, but it works now.
I could not find any track on redisson-spring-data of what version should be used in what conditions, so I just tried another version ... and it worked!
Hope that helps.
专注分享java语言的经验与见解,让所有开发者获益!
评论