我尝试使用spring native来创建spring应用程序的本机映像,它使用kafkassl。
但是我有一个问题要通过Kafka信任库的绝对路径。
因为本机映像不知道信任库路径在哪里。
Spring Boot:2.4.5
spring原生版本:0.9.2
graalvm:graalvm-ce-java8-21.0.0.2
我的信任库文件位于以下路径中
src
- main
- resources
- truststore
mytrustsotre.jks
# Kafka properties
spring:
kafka:
ssl:
trustStorePassword: "password"
trustStoreLocation: "classpath:truststore/mytrustsotre.jks"
maven插件生成参数
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder:tiny</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
-H:IncludeResourceBundles=sun.security.util.Resources
-H:IncludeResources=truststore/mytrustsotre.jks
</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
</image>
</configuration>
</plugin>
生成并运行应用程序
mvn spring-boot:build-image -Dspring-boot.build-image.imageName=my.way.com/app:1.0.0-SNAPSHOT
...
...
docker run -it -e "SPRING_PROFILES_ACTIVE=default" \
-e "--spring.application.name=app" \
my.way.com/app:1.0.0-SNAPSHOT
当消息到达时,就会发生错误。
Caused by: java.lang.IllegalStateException: Resource 'class path resource [truststore/mytrustsotre.jks]' must be on a file system
at org.springframework.boot.autoconfigure.kafka.KafkaProperties$Ssl.resourceToPath(KafkaProperties.java:1155) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
at org.springframework.boot.context.properties.PropertyMapper$Source.lambda$as$2(PropertyMapper.java:220) ~[na:na]
at org.springframework.boot.context.properties.PropertyMapper$Source.to(PropertyMapper.java:314) ~[na:na]
at org.springframework.boot.autoconfigure.kafka.KafkaProperties$Ssl.buildProperties(KafkaProperties.java:1143) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
at org.springframework.boot.autoconfigure.kafka.KafkaProperties.buildCommonProperties(KafkaProperties.java:159) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
at org.springframework.boot.autoconfigure.kafka.KafkaProperties.buildProducerProperties(KafkaProperties.java:190) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
at com.naver.gla.pgsync.config.ApplicationConfiguration.producerFactory(ApplicationConfiguration.kt:70) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
at com.naver.gla.pgsync.config.ApplicationConfiguration.producer(ApplicationConfiguration.kt:73) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[na:na]
... 49 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [truststore/mytrustsotre.jks] cannot be resolved to absolute file path because it does not reside in the file system: resource:truststore/mytrustsotre.jks
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217) ~[na:na]
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:154) ~[na:na]
at org.springframework.boot.autoconfigure.kafka.KafkaProperties$Ssl.resourceToPath(KafkaProperties.java:1152) ~[com.naver.gla.pgsync.PgSyncApplicationKt:na]
... 58 common frames omitted
如果没有本机映像,此应用程序可以正常工作。
如何将绝对路径传递给本机映像?
1条答案
按热度按时间vfhzx4xs1#
我自己解决这个问题。
我将docker卷设置为主机中信任文件的链接。