我在这里发现了两篇类似的帖子,但其中一篇尚未得到答复,另一篇是关于 android 的。我有一个 Spring Boot 项目,我想在我的应用程序中访问 GCP 存储文件。
本地一切正常,我可以访问我的存储桶并读取以及将文件存储在我的存储中。但是当我将其上传到 gcp kubernetes 时,出现以下异常:
"java.nio.file.FileSystemNotFoundException: Provider "gs" not installed at java.nio.file.Paths.get(Paths.java:147) ~[na:1.8.0_212] at xx.xx.StorageService.saveFile(StorageService.java:64) ~[classes!/:0.3.20-SNAPSHOT]
我的代码行如下所示:
public void saveFile(MultipartFile multipartFile, String path) {
String completePath = filesBasePath + path;
Path filePath = Paths.get(URI.create(completePath)); // <- exception appears here
Files.createDirectories(filePath);
multipartFile.transferTo(filePath);
}
}
completePath 可能会导致类似“gs://my-storage/path/to/file/image.jpg”的结果
我有以下依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-storage</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-nio</artifactId>
<version>0.122.5</version>
</dependency>
有人知道哪里可以看吗? 除了基础设施之外,唯一真正的区别是我没有明确不在 kubernetes 上使用身份验证,因为根据文档不需要它
When using Google Cloud libraries from a Google Cloud Platform environment such as Compute Engine, Kubernetes Engine, or App Engine, no additional authentication steps are necessary.
最佳答案
看起来这里传统的 Spring boot 打包并没有以所需的方式打包依赖项。通常您会看到类似以下内容:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.5</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
但是,为了可以访问“gs”提供程序,它需要位于“lib/”文件夹中。您可以通过复制依赖项然后创建 JAR 来手动打包它(这基于 springboot-helloworld 示例:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>
com.example.appengine.springboot.SpringbootApplication
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
关于java - 提供程序 "gs"未安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66144214/