【问题标题】:How run spring boot jar with class path resource如何使用类路径资源运行 Spring Boot jar
【发布时间】:2021-12-30 06:00:42
【问题描述】:

我有一个 Spring Boot 应用程序。如果我从 Eclipse 运行它,它会完美运行。但是如果我在命令提示符下运行相同的命令,我会收到以下错误

错误

org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.kafka.core.ProducerFactory]:工厂方法'kafkaProducerFactory'抛出异常;嵌套异常是 java.lang.IllegalStateException: Resource 'class path resource [kafka/somejksfile.jks]' must be on a file system\r\n\tat

我提取了 .jar 文件,并且能够在其中看到与 Kafka 相关的 .jks 文件
项目名称\BOOT-INF\类

由于某种原因,它没有选择 src/main/resources 中的所有文件。从命令提示符运行 .jar 时如何引用该位置。我尝试了以下没有运气

java -jar -Dspring.profiles.active=dev -Dspring.config.location=file:\\C:\my-files\poc\projectName\src\main\resources\ api-account-info.jar

注意:我无法更改任何代码

【问题讨论】:

  • 它必须是文件系统上的文件,而不是 jar 中的打包资源,这也是错误告诉您的内容。因此,您不能(显然)将此文件打包到 jar 中并运行它。它可以在 eclipse 中工作,因为它是文件系统上的物理文件。

标签: spring spring-boot command-line


【解决方案1】:

我通过以下方式解决了这个问题。

  1. 下载 Spring Boot CLI 并解压。 (https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.2/spring-boot-cli-2.6.2-bin.zip)
  2. 设置环境变量

变量:SPRING_HOME 值:C:\my-files\Installations\spring-boot-cli-2.6.2-bin\spring-2.6.2

变量:路径 值:%SPRING_HOME%\bin

  1. 从命令提示符运行以下命令

SET SPRING_PROFILES_ACTIVE=dev mvn spring-boot:run

这将构建并启动应用程序。

【讨论】:

    猜你喜欢
    • 2017-09-07
    • 2018-03-18
    • 2021-08-02
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 2010-12-26
    相关资源
    最近更新 更多