@Value not working properly with @ActiveProfiles

Viewed 235

I have several beans using @Value annotion in my project.
If I don't use @ActiveProfiles and run test with config below,everything is fine.

spring:
  profiles:
    active: localhost,schedule_off

But if I use @ActiveProfiles,there would be exception says

'Could not resolve placeholder XXX'.

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("localhost,schedule_off")

Why is that and how to fix it?

2 Answers

The actual problem is (simply):

@ActiveProfiles takes rather a String[] than a comma separated string parameter.

So please try (the decently different):

@ActiveProfiles({"localhost", "schedule_off"})

instead (tested/works!;).

how about this?

spring:
  config:
    activate:
      on-profile: localhost,schedule_off
Related