【问题标题】:Spring Boot Maven Build Problem with Random Values in application.properties在 application.properties 中随机值的 Spring Boot Maven 构建问题
【发布时间】:2019-03-21 00:35:18
【问题描述】:

例如,我编辑了来自

的 application.properties
spring.mail.host=stmp.test.com

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

我在开始时将这些属性覆盖为正确的值。在我想运行 maven 来构建我的应用程序之前,这可以正常工作。

我收到以下异常

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

我认为问题在于 maven 也需要这些值,但我可以如何以及在哪里插入它们?我不想在 cli 上运行 mvn。

【问题讨论】:

  • 你看this了吗?
  • 首先,感谢您的回答。我不希望我的源代码中有任何凭据,并且 pom.xml 也是其中的一部分。我稍后会将这个项目上传到 git,因此我需要从外部进行配置。

标签: java eclipse maven spring-boot


【解决方案1】:

我认为@Nicholas K 表明您可以在 maven 命令中传递这些值。例如使用参数mvn spring-boot:run "-Dserver.mail.host=mailhost"

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

export SERVER_MAIL_HOST=mailhost

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

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

default it to an empty string

【讨论】:

  • 感谢您的回答。我试图在选项卡环境下创建所有这些变量。没有任何运气。之后,我用 export ... 创建了所有 env 环境变量,也没有任何运气。同样的例外。我也在cli上尝试过,没有任何运气。疯了吧。不太清楚为什么只使用一些应该覆盖的参数来运行 maven 构建是如此困难。
  • 会不会是像 stackoverflow.com/questions/39375016/… 这样的不同问题?未能处理导入候选消息的消息不一定相关。也许您可以发布更多堆栈跟踪
  • org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类 [com.skidata.hosting.certselfservice.CertSelfServiceApplication] 的导入候选;嵌套异常是 java.lang.IllegalStateException: Error processing condition on org.springframework.context.annotation.ConfigurationClassParser.processImports (ConfigurationClassParser.java:648) ~[spring-context-5.0 .7.RELEASE.jar:5.0.7.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassParser.lambda
  • 如果您尝试为这些值设置默认值,它仍然会失败吗?
  • 您还应该能够覆盖整个属性文件,方法是在您的 jar 旁边的 /config/ 目录中放置一个不同的文件 - docs.spring.io/spring-boot/docs/current/reference/html/…
猜你喜欢
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 2016-08-10
  • 2016-07-17
  • 2019-02-11
  • 1970-01-01
  • 2014-06-02
  • 2015-11-03
相关资源
最近更新 更多