如何在定义为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引导插件,如下所示:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Djasypt.encryptor.password=xxx"
在这里查看插件的文档:spring-boot-maven插件文档
另一种选择是将其设置在pom.xml
中
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Djasypt.encryptor.password=xxx
</jvmArguments>
</configuration>
</plugin>