title: How to disable Services on run- or startuptime in Spring?
body: <p>In our standalone Spring 3.1 Application we divided the Business logic from a Monitoring Swing View strictly. The view get its information by implementing an <code>EventListener</code> interface.</p>
  
  <p>To disable the UI it would be enough to "remove" all the <code>@Services</code> on the UI Beans so that the UI Class that implements this EventListner get not Injected by the Business logic.</p>
  
  <p>But how to do this?</p>
  
  <p>This Example gives a small Oerview of our classes:</p>
  
  <pre><code>@Service
  public class UI extends JFrame implements EventListener {
      @PostConstruct
      public void setup() {
          // Do all the Swing stuff
          setVisible(true);
      }
  
      @Override
      public void onBusinessLogicUpdate(final State state) {
          // Show the state on the ui
      }
  }
  
  @Service
  public class Businesslogic {
      @Autowired
      public List&lt;EventListener&gt;  eventListeners;
  
      public void startCalculation() {
  
          do {
              // calculate ...
              for (final EventListener listener : this.eventListeners) {
                  eventlistener.onBusinessLogicUpdate(currentState);
              }
          }
          while(/* do some times */);
      }
  }
  
  public class Starter {
      public static void main(final String[] args) {
          final ApplicationContext context = // ...;
  
          if(uiShouldBedisabled(args)) {
              // remove the UI Service Bean
          }
  
          context.getBean(Businesslogic.class).startCalculation();
      }
  }
  </code></pre>