Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
marcingrzejszczak opened this issue Dec 30, 2016 · 6 comments
Labels

Comments

@marcingrzejszczak
Copy link
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

@marcingrzejszczak
Copy link
Contributor Author

marcingrzejszczak commented Mar 10, 2017

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
Copy link
Member

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

@spencergibb
Copy link
Member

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

@vicusbass
Copy link

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
Copy link

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
Copy link
Contributor Author

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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants