java - 如何为 Maven 命令行附加 VM 选项
问题描述
如何在定义为 VM 选项的 maven 命令行中添加参数。在 Intellij 我有配置
java 11 -Djasypt.encryptor.password=xxx
当我在配置类中使用 @Value 注释读取 VM 选项时,该解决方案非常有效。
@Value("${jasypt.encryptor.password}")
private String jasyptEncryptorPassword;
我正在使用以下命令 mvn -Djasypt.encryptor.password=xx spring-boot:run 但它无法获取并出现以下错误。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jasyptConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jasypt.encryptor.password' in value "${jasypt.encryptor.password}"
只有命令 java -jar 可以附加 VM 选项?
解决方案
您可以将 VM 选项附加到 Spring Boot 插件,如下所示:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Djasypt.encryptor.password=xxx"
在此处检查插件的文档:spring-boot-maven-plugin docs
其他选项是将其设置在pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Djasypt.encryptor.password=xxx
</jvmArguments>
</configuration>
</plugin>
推荐阅读
- json - 显示来自外部 url 的 json 数组中的数据,没有 api
- excel - 如何使用 VBA 将函数插入到单元格中?
- html - div 在表数据内的段落内。它有效吗?
- python - 按百分比计算每月和每周的入住率
- c++ - C++ 从 'int' 到 'int*' 的无效转换 [-fpermissive]
- r - 具有 10,000 个组的 geom_line
- python-3.x - 用于按下按钮的 Tkinter 打印键:如何从事件中提取字符?
- javascript - onClick 未定义 MERN 堆栈
- vim - 如何在插入模式下取消 vim 粘贴?
- python - 如何将 Int64 列转换为浮点数