1

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.

Mister Lamp
  • 345
  • 1
  • 4
  • 13
  • 2
    Did you look at [this](https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml)? – Nicholas K Oct 16 '18 at 13:13
  • First, thanks to your answer. I don't want any credentials in my source code and the pom.xml is also part of that. I will upload this project to git later and therefore I need the possibility to config from outside. – Mister Lamp Oct 16 '18 at 13:18

1 Answers1

0

I think @Nicholas K was making the point that you can pass in those values in you maven command. For example with the argument mvn spring-boot:run "-Dserver.mail.host=mailhost".

You can also set an environment variable and that should be injected:

export SERVER_MAIL_HOST=mailhost

Or if you sometimes don't want to set them you could set a default for the property in your properties file:

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

Or default it to an empty string

Ryan Dawson
  • 11,832
  • 5
  • 38
  • 61
  • Thank you for your answer. I tried to create under the tab environment all these variables. Without any luck. After that I created all env environment variables with export ... also without any luck. Same Exception. I also tried it on the cli without any luck. This is insane. Not quite sure why it is so hard to run a maven build only with some parameters which should be overwritten. – Mister Lamp Oct 16 '18 at 14:28
  • Could it be a different issue like https://stackoverflow.com/questions/39375016/failed-to-process-import-candidates-for-configuration-class ? That failed to process import candidates message isn't necessarily related. Perhaps you can post more of your stacktrace – Ryan Dawson Oct 16 '18 at 14:36
  • org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.skidata.hosting.certselfservice.CertSelfServiceApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:648) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.lambda – Mister Lamp Oct 16 '18 at 14:58
  • If you try setting the defaults for the values does it still fail? – Ryan Dawson Oct 16 '18 at 16:25
  • Yes, with the default values its working fine and I can build the application again. Thanks so far, but now I have the passwords again in the file which I wanted to avoid. – Mister Lamp Oct 17 '18 at 10:21
  • 1
    You should also be able to override the whole properties file by putting a different on in a /config/ directory alongside your jar - https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html – Ryan Dawson Oct 17 '18 at 10:28
  • Also perhaps try "spring.mail.host=${SERVER_MAIL_HOST:defaultmailhost}" in the properties file – Ryan Dawson Oct 17 '18 at 10:37
  • I will check that out. Thanks again! – Mister Lamp Oct 17 '18 at 10:39