Skip to content

Can't override properties from bootstrap.yml in profile specific bootstrap file #156

Closed
@marcingrzejszczak

Description

@marcingrzejszczak
Contributor

Having bootstrap.yml in the main sources

spring:
  application:
    name: edgeService
  cloud:
    consul:
      config:
        enabled: false
        prefix: config
        profileSeparator: '@@'
        watch:
          enabled: false
      discovery:
        tags: version=@project.version@
      host: localhost
      port: 8500
  main:
    banner-mode: 'off'

and having the bootstrap-ci.yml and @ActiveProfiles("ci") in the tests

spring:
  application:
    name: edgeService
  cloud:
    consul:
      discovery:
        scheme: http
      enabled: false
      config:
        enabled: false
... (other app-specific configs removed)
stubrunner:
  ids: com.acme:security.service:1.0.0:stubs
  idsToServiceIds:
    security.service: securityService

Doesn't lead to overriding the values from bootstrap.yml . In other words the app is always trying to connect to Consul.

Related issues:
spring-cloud/spring-cloud-contract#174
spring-cloud/spring-cloud-contract#141

Activity

marcingrzejszczak

marcingrzejszczak commented on Mar 10, 2017

@marcingrzejszczak
ContributorAuthor

The current workaround for this is to use a static block like this:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureStubRunner(ids = {"com.ryanjbaxter.spring.cloud:ocr-participants:+:stubs"}, workOffline = true)
@DirtiesContext
@ActiveProfiles("test")
public class OcrRacesApplicationTestsBase {

    @Autowired
    protected ParticipantsService participantsService;

    private List<Participant> participants = new ArrayList<>();


    //Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156
    static {
        System.setProperty("eureka.client.enabled", "false");
        System.setProperty("spring.cloud.config.failFast", "false");
    }

    @Before
    public void setup() {
        this.participants = new ArrayList<>();
        this.participants.add(new Participant("Ryan", "Baxter", "MA", "S", Arrays.asList("123", "456")));
        this.participants.add(new Participant("Stephanie", "Baxter", "MA", "S", Arrays.asList("456")));
    }

    @After
    public void tearDown() {
        this.participants = new ArrayList<>();
    }

    @Test
    public void contextLoads() {
        List<Participant> participantList = participantsService.getAllParticipants();
        assertEquals(participants, participantList);
    }
}
spencergibb

spencergibb commented on Apr 4, 2017

@spencergibb
Member

This works in general, so I wonder if it is specific to tests and @ActiveProfiles.

spencergibb

spencergibb commented on Apr 4, 2017

@spencergibb
Member

hmm, I wrote a test that uses @ActiveProfiles with a profile specific bootstrap.yml and it overrides the value just fine.

vicusbass

vicusbass commented on Apr 6, 2017

@vicusbass

The workaround specified by Marcin works fine, but if a test fails, the failure reason does not offer any indication on what the problem is, but it points to Hystrix.

vicusbass

vicusbass commented on May 4, 2017

@vicusbass

While using the following versions:

<spring.boot.version>1.5.3.RELEASE</spring.boot.version>
<spring.cloud.version>Dalston.RELEASE</spring.cloud.version>

the static block is not needed anymore while having the following configuration in bootstrap.yml:

spring:
  profiles: dev,test
  cloud:
    consul:
      discovery:
        enabled: false
      config:
        enabled: false
    service-registry:
      auto-registration:
        enabled: false
marcingrzejszczak

marcingrzejszczak commented on May 4, 2017

@marcingrzejszczak
ContributorAuthor

So we can close it since it got fixed in Dalston.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @spencergibb@marcingrzejszczak@vicusbass

        Issue actions

          Can't override properties from bootstrap.yml in profile specific bootstrap file · Issue #156 · spring-cloud/spring-cloud-commons