java - 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.
解决方案
我认为@Nicholas K的意思是你可以在你的 maven 命令中传递这些值。例如与论点mvn spring-boot:run "-Dserver.mail.host=mailhost"
。
您还可以设置一个环境变量并且应该被注入:
export SERVER_MAIL_HOST=mailhost
或者,如果您有时不想设置它们,您可以在属性文件中为属性设置默认值:
spring.mail.host=${server.mail.host:defaultmailhost}
或者默认为空字符串
推荐阅读
- vim - 如何在 VIMWIKI 中对按时间排序的 VimwikiGeneratedLink 进行排序?
- python - 如何在列表中找到不是 X 数的最大数?
- typescript - 当 TypeScript 接口同时描述一个对象和一个函数时,它怎么能被使用呢?
- c - 线程共享局部变量?
- r - 使用带模式的行计算值
- python - 添加基于 RadioItems 的下拉列表
- php - sum(value) AS "Variable" SQL 的未定义变量
- elixir - 当你在 Elixir 中只有一个函数定义时,使用守卫是惯用的吗?
- html - 页面底部的页脚
- flutter - 触发键盘显示 Flutter