0

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

CjRobin
  • 161
  • 1
  • 1
  • 14
  • 1
    Looks like this was answered [here](https://stackoverflow.com/questions/24176399/how-do-i-filter-test-resources-in-maven/24176400). – Hopey One Jun 04 '21 at 01:55
  • Awesome! I was following your initial comment and was disappointed when nothing happened (as it seemed very promising), but adding testResources instead did the trick. Thank you so much @HopeyOne – CjRobin Jun 04 '21 at 02:10

0 Answers0