【发布时间】:2020-05-26 02:49:26
【问题描述】:
我正在使用SpringBoot 2.1.3,我正在尝试通过命令行传递一些参数。
这是main 类:
@SpringBootApplication
@Slf4j
public class Application implements CommandLineRunner {
@Value("${priceOne.pound}")
private Integer p1pound;
@Value("${priceOne.shilling}")
private Integer p1shilling;
@Value("${priceOne.pences}")
private Integer p1pences;
@Value("${priceTwo.pound}")
private Integer p2pound;
@Value("${priceTwo.shilling}")
private Integer p2shilling;
@Value("${priceTwo.pences}")
private Integer p2pences;
@Value("${factor}")
private Integer factor;
@Value("${op}")
private String op;
public static void main(String[] args) {
SpringApplication.run(EurisApplication.class, args);
}
@Override
public void run(String... args) {
Price priceOne = new Price(p1pound, p1shilling, p1pences);
Price priceTwo = new Price(p2pound, p2shilling, p2pences);
....
....
}
我尝试用以下内容填充这些变量:
spring-boot:run -Drun.arguments=--priceOne.pound=5, --priceOne.shilling=5, --priceOne.pences=5, --priceTwo.pound=5, --priceTwo.shilling=5, --priceTwo.pences=5, --factor=0, --op=+
或与:
spring-boot:run -Dspring-boot.run.arguments=--priceOne.pound=5, --priceOne.shilling=5, --priceOne.pences=5, --priceTwo.pound=5, --priceTwo.shilling=5, --priceTwo.pences=5, --factor=0, --op=+
如果我在参数列表的开头和结尾添加引号" ",则会出现转换错误..
你能帮帮我吗?
非常感谢。
感谢您的回复!
如果我删除除第一个参数之外的所有参数,然后启动应用程序:
spring-boot:run -Dspring-boot.run.arguments=--priceOne.pound=5
工作正常。您提到的其他方式:
spring-boot:run --priceOne.pound=5
用一个参数和多个参数检索解析异常。我有点糊涂了。。
编写整个应用程序花费的时间比编写该死的commandLine 启动要少。我无法将所有参数作为单个 String.. 我不明白为什么只有一个参数有效而两个参数无效!
谢谢
【问题讨论】:
标签: spring-boot command-line-arguments