{"action":"closed","issue":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-commons/issues/78","repository_url":"https://api.github.com/repos/spring-cloud/spring-cloud-commons","labels_url":"https://api.github.com/repos/spring-cloud/spring-cloud-commons/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-commons/issues/78/comments","events_url":"https://api.github.com/repos/spring-cloud/spring-cloud-commons/issues/78/events","html_url":"https://github.com/spring-cloud/spring-cloud-commons/issues/78","id":124725306,"number":78,"title":"How to prevent listener from firing in bootstrap context","user":{"login":"pawelszymczyk","id":6159409,"avatar_url":"https://avatars.githubusercontent.com/u/6159409?v=3","gravatar_id":"","url":"https://api.github.com/users/pawelszymczyk","html_url":"https://github.com/pawelszymczyk","followers_url":"https://api.github.com/users/pawelszymczyk/followers","following_url":"https://api.github.com/users/pawelszymczyk/following{/other_user}","gists_url":"https://api.github.com/users/pawelszymczyk/gists{/gist_id}","starred_url":"https://api.github.com/users/pawelszymczyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pawelszymczyk/subscriptions","organizations_url":"https://api.github.com/users/pawelszymczyk/orgs","repos_url":"https://api.github.com/users/pawelszymczyk/repos","events_url":"https://api.github.com/users/pawelszymczyk/events{/privacy}","received_events_url":"https://api.github.com/users/pawelszymczyk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-commons/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-04T09:42:53Z","updated_at":"2016-03-18T14:18:54Z","closed_at":"2016-03-18T14:18:54Z","body":"Hi \r\n\r\nThis issue is continuation of https://github.com/spring-cloud/spring-cloud-config/issues/314. \r\n\r\nI think I have to describe the situation more precisely.\r\n\r\nAs I mentioned before I have a application based on Spring-boot and I have a [CommandLinePropertiesApplicationListener](https://github.com/pawelszymczyk/spring-cloud-config-example/blob/master/src/main/java/pl/pawel/CommandLinePropertiesApplicationListener.java) that listens on ApplicationEnvironmentPreparedEvent events. The listener adds `JOptCommandLinePropertySource` which reads `-environment` program argument and bind it into externalized configuration properties - [ApplicationProperties](https://github.com/pawelszymczyk/spring-cloud-config-example/blob/master/src/main/java/pl/pawel/ApplicationProperties.java). \r\n\r\nThis properties are injected into [ConfigurationServiceClientBootstrap](https://github.com/pawelszymczyk/spring-cloud-config-example/blob/master/src/main/java/pl/pawel/ConfigurationServiceClientBootstrap.java) class which is creating as `org.springframework.cloud.bootstrap.BootstrapConfiguration`:\r\n\r\n```\r\n# Bootstrap components\r\norg.springframework.cloud.bootstrap.BootstrapConfiguration=\\\r\npl.pawel.ConfigurationServiceClientBootstrap\r\n```\r\n\r\nThis configuration reads variable `environment` from ApplicationProperties and do some things according this property (eg. find URI to Configuration Service via Discovery Service).\r\nThe problem is that `bootstrapInProgress` phase overridden ApplicationProperties values. \r\n\r\nEverything I mention here is showed in some tiny application created specially for this issue: https://github.com/pawelszymczyk/spring-cloud-config-example. \r\nYou can run it by executing unit test from class: [CommandLinePropertiesApplicationListenerTest](https://github.com/pawelszymczyk/spring-cloud-config-example/blob/master/src/test/java/pl/pawel/CommandLinePropertiesApplicationListenerTest.java). \r\nTest is failing now, to fix it you can uncomment line containing `if (event.getEnvironment().getPropertySources().contains(\"bootstrapInProgress\"))` here: \r\n\r\nhttps://github.com/pawelszymczyk/spring-cloud-config-example/blob/master/src/main/java/pl/pawel/CommandLinePropertiesApplicationListener.java#L25\r\n\r\nHope this helps :)"}}