简体   繁体   中英

loading springboot properties from a Json file using -Dspring.application.json

I am trying to run the springboot application using the below command and passing the properties using -Dspring.application.json

mvnw spring-boot:run -Dspring.application.json = "{"Api": {"gateway": {"password": "abc"}}}"

tried using single quotes instead of double mvnw spring-boot:run -Dspring.application.json = '{"Api": {"gateway": {"password": "abc"}}}'

error thrown: No plugin found for prefix ''{Api' in the current project and in the plugin groups.

How do I resolve this error, Is there anything that I am missing here?

If you want to launch your application with the Spring-Boot Maven plugin, you can't directly use spring.application.json argument here. You have to use the spring-boot.run.arguments argument of the plugin to pass arguments to you application. Here is how:

mvnw spring-boot:run -Dspring-boot.run.arguments="--spring.application.json='{\"Api\": {\"gateway\": {\"password\": \"abc\"}}}'"

As you can see, you also have to espace double quotes so that they are not interpreted as delimiter of the command line argument.

Maybe you already know and you need to use json, but there is an easier way to achieve this:

mvnw spring-boot:run -Dspring-boot.run.arguments="--Api.gateway.password='abc'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM