title: Can you stop Spring Cloud rebinding/reloading POJOs annotated with @ConfigurationProperties?
body: <p>If you annotate a POJO with <code>@ConfigurationProperties</code>, it allows you to easily load properties from a (<code>yml</code>) properties file and make them available at runtime.</p>
  
  <p>However, when Spring Cloud is on the classpath, the behaviour changes somewhat: the POJO is now <a href="http://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_environment_changes" rel="nofollow noreferrer">re-bound</a> whenever an <code>EnvironmentChangeEvent</code> is fired. That's great, unless you have manipulated the properties at app startup somewhat - those changes can now get overridden at any point.</p>
  
  <p>Is there a way to stop that from happening (e.g. by adding another annotation to that class to say "never" rebind)?</p>
  
  <p>In particular, I have a <code>@SpringBootTest</code>-annotated test class where a library I use is dynamically generating a port number. I'm accessing that number in my <code>@Before</code> method, and want to "inject" it into the POJO, so the app under test picks it up and connects to that port (i.e. the equivalent to <code>-Dmy.port=0000</code> at JVM launch). What would be a better way to achieve that (if switching off the rebinding and just assigning the value to the right field doesn't work or is the wrong approach)? </p>
  
  <p>I have tried setting it via <code>System.setProperty()</code>, unsurprisingly with little success, or to add it via adding a new <code>PropertySource</code> to the <code>ApplicationContext</code>, and by using the <code>TestPropertySourceUtil.addInlinePropertiesToEnvironment()</code> - all to no avail...</p>