Home > OS >  @Value not working properly with @ActiveProfiles
@Value not working properly with @ActiveProfiles

Time:12-20

I have several beans using @Value annotion in my project.
If I don't use @ActiveProfiles and run text 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?

CodePudding user response:

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!;).

CodePudding user response:

how about this?

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