0

Not sure what I'm doing wrong here, but I have the following value that points to the URL of a micro service.

@Value("${url.dispenseRoot}")
private String dispenseRoot;

And I am setting up my dev profile in my application.yml file such:

---
spring:
  datasource:
    url: jdbc:h2:mem:test
    username: sa
    password: sa
    driverClassName: org.h2.Driver
  config:
    activate:
      on-profile: dev

mpesa:
  host: sandbox.safaricom.co.ke
  port: 443

url:
  dispenseRoot: https://localhost:8844/dispense
---

Then, in accordance with my answer here: How do I activate a Spring Boot profile when running from IntelliJ?, I set up the spring boot profile on the run configuration as such:

enter image description here

And then run the following test to test my configuration:

@SpringBootTest
public class PaymentApplicationTests {

    @Test
    public void contextLoads() {
    }

}

And I get:

    ... 111 more
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'url.dispenseRoot' in value "${url.dispenseRoot}"

Now, if I copy and paste the following lines:

url:
  dispenseRoot: https://localhost:8844/dispense

Above my profile where I'm setting up the general settings that are true for everything, it works fine. Therefore, I'm certain it has something to do with profiles, but I can't figure out what it is.

Please advise...

3
  • 1
    The file name of your properties is wrong. It should be application-dev.yml Commented Aug 11, 2021 at 9:00
  • could you clarify what you mean with "Above my profile where I'm setting up the general settings that are true for everything" ? Commented Aug 11, 2021 at 9:15
  • Your tests are probably run with a test-profile, meaning you need a separate properties-file in your test/resources dir. Be warned that the @Value annotation doesn't work for unit tests, so if you need to populate the field you have to do it via reflection. Commented Aug 11, 2021 at 10:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.