[英]Spring Boot Redis error when dockerized, but not with maven run
我正在使用 Redis(帶有 redisson)構建一個帶有 Spring 引導的應用程序。
當我在開發模式下運行我的應用程序時,它工作正常,但是當我嘗試在 docker 容器中運行它時,它失敗並出現錯誤
java.lang.ClassNotFoundException:org.springframework.data.redis.connection.ReactiveStreamCommands
我的 maven 配置為 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>
我的 maven 配置構建 docker 容器:
<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>
當我登錄到我的容器並分析我的 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
這與我使用 jar 進行開發時得到的完全相同。
這是關於我如何啟動 redis 的 docker-compose 摘錄:
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 嗎? 提前致謝
我找到了一個解決方案:
我沒有使用redisson-spring-data-22
,而是降級為redisson-spring-data-16
(因為我注意到使用的 spring-data-redis 的有效版本實際上是 2.1.5,低於 2.2.. .)。
我無法解釋為什么真的,但它現在有效。
我在redisson-spring-data上找不到任何關於在什么條件下應該使用哪個版本的曲目,所以我只是嘗試了另一個版本……它成功了!
希望有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.