title: How do you handle configuration on spring framework when developing custom libraries intended to be consumed by other applications?
body: <p>I'm working on building a custom "event" library that encapsulates the technical details of an event buffer we are planning to share with multiple consumers. Ideally, we want this library to use the spring framework (note: not spring boot), and be environmentally aware. Something I am not groking from the current docs is how to make the library environmentally aware.</p>
  
  <p>For example, we want to include with the library a static configuration for the queue end points the library will publish / consume from; however, we want to enable "overriding" these queues when in the development or integration environments. Ideally, I do not want to make multiple builds that swap out what the config file is, but include them all and know to read the "right" one.</p>
  
  <p>Some of the things I am not understanding; 
  How to pass in a "profile" when debugging (it seems the Environment object won't honor the -Dspring.active.profiles property).
  How to structure the @Configuration classes so that you do not hard code @Profile(prod).</p>
  
  <p>Total Spring n00b, thanks in advance!</p>
  
  <p>---UPDATE: Trying to provide a more concrete example.</p>
  
  <p>So I have create a basic configuration class to hold the details that would be populated by configuration files:</p>
  
  <pre><code>@Configuration
  public class EventConfiguration implements EnvironmentAware{
  
  
  
  private static Environment env = null;
  
      @Value("${events.queue1}")
      private String queue1;
      @Value("${events.queue2}")
      private String queue2;
  
  
      @Bean
      public EventDispatcher eventDispatcher() {
          return new EventDispatcher(this);
      }
  
      @Override
      public void setEnvironment(Environment environment) {
          env = environment;
      }
      ... getters and setters
  </code></pre>
  
  <p>Essentially I want to either go the yaml approach and define the queues by environment "dev", "integration", "prod"; or have 3 different files following the application-{env}.properties convention.</p>
  
  <p>Then, to help me understand how this works, I threw together a quick test so I can inspect the configuration / environment:</p>
  
  <pre><code>@Test
  public void testContext() {
  
      AnnotationConfigApplicationContext ctx =
               new AnnotationConfigApplicationContext();
      Environment env = ctx.getEnvironment();
      ctx.scan("com...events");
      ctx.refresh();
  
      EventDispatcher dispatcher = ctx.getBean(EventDispatcher.class);
  
  }
  </code></pre>
  
  <p>I started the debugger with a -Dspring.profiles.active=dev, after having created an application-dev.profile available on the class path.</p>
  
  <p>Am I on the right track? Seems weird to have to have that type of boiler plate code to instantiate the objects, plus it didnt work. The Environment object only showed "default" as the active profile.</p>