I added a new functionality to my service where I now consume messages from rabbitMq. This works great and pretty much right out of the box with Spring Boot.
However, in order to not add the credentials to source control, I have been trying to inject the password from my user's settings.xml. This works as intended when I stand up the service locally with its default/production profile, but it does not when I run the test suite (test profile).
Below is an example of my settings.xml:
<settings
...
<profiles>
<profile>
<id>inject-properties</id>
<properties>
<prod.rabbit.pwd>someProdPwd</prod.rabbit.pwd>
<test.rabbit.pwd>someTestPwd</test.rabbit.pwd>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>inject-properties</activeProfile>
</activeProfiles>
</settings>
I run mvn help:active-profiles
to validate it activates:
The following profiles are active:
- inject-properties (source: external)
- package (source: com.myservice:myservice:1.16.0-SNAPSHOT)
Then, in my application.properties I define the property as follows:
spring.rabbitmq.password=@prod.rabbit.pwd@
I stand up the service, and I can see the property being replaced by the value in settings.xml, so that part looks good.
Then, in my application-test.properties, I have:
spring.rabbitmq.password=@test.rabbit.pwd@
But when I proceed to run my tests, that does not work as it did before. When the rabbit bean is instantiated by the spring boot context builder, it passes the literal value @test.rabbit.pwd@
, which fails authentication and causes the service not to stand up/test not to run.
Anyone ever run into this weird behavior? I found this question, which is pretty much the same issue I am having from a while back, but it did not really have a solution. Replace property placeholders in spring profile-specific properties file