首页 > 解决方案 > Spring Boot Maven Build Problem with Random Values in application.properties

问题描述

I have edited, for example, application.properties from

spring.mail.host=stmp.test.com

to

spring.mail.host=${server.mail.host}

and I override at starttime these properties to the correct values. This works fine until I want to run maven to build my application.

I receive the following Exception

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class

I think the problem is that maven also needs these values but how and where can I insert them? I dont want to run mvn on the cli.

标签: javaeclipsemavenspring-boot

解决方案


我认为@Nicholas K的意思是你可以在你的 maven 命令中传递这些值。例如与论点mvn spring-boot:run "-Dserver.mail.host=mailhost"

您还可以设置一个环境变量并且应该被注入:

export SERVER_MAIL_HOST=mailhost

或者,如果您有时不想设置它们,您可以在属性文件中为属性设置默认值:

spring.mail.host=${server.mail.host:defaultmailhost}

或者默认为空字符串


推荐阅读