【问题标题】:How do I get command line args when using `spring-boot:run`使用`spring-boot:run`时如何获取命令行参数
【发布时间】:2022-01-17 08:22:36
【问题描述】:

我有以下 Scala 代码...

object TestCompany extends App {
  SpringApplication run classOf[TestCompanyApp]
}
@SpringBootApplication
class TestCompanyApp extends CommandLineRunner{
  override def run(args: String*): Unit = {
    println(args.mkString("|"))
  }
}

我尝试像mvn clean install spring-boot:run -Dspring-boot.run.arguments=argOne,argTw 一样运行,但 args 仍然是空的。我错过了什么?

【问题讨论】:

    标签: spring spring-boot scala


    【解决方案1】:

    我需要像这样将数组转换为可变参数...

    object TestCompany {
      def main(args: Array[String]): Unit = {
        SpringApplication.run(classOf[TestCompanyApp], args:_*)
      }
    }
    

    现在可以了...

    mvn clean install spring-boot:run -Dspring-boot.run.arguments=test

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多