title: Detecting unused Spring beans
body: <p>Given a Spring configuration that exclusively contains eager (non-lazy) singleton beans, i.e. the defaults, is it possible to have Spring throw an exception in the case where any of those beans is not injected anywhere? I'm essentially looking for a way to detect dead code in the form of Spring beans.</p>
  
  <p>My question is somewhat similar to these.</p>
  
  <ul>
  <li><a href="http://forum.spring.io/forum/spring-projects/container/116494-any-tools-or-method-to-identify-unused-spring-beans" rel="noreferrer">http://forum.spring.io/forum/spring-projects/container/116494-any-tools-or-method-to-identify-unused-spring-beans</a></li>
  <li><a href="https://stackoverflow.com/questions/4023477/spring-instantiation-and-unused-beans">Spring Instantiation and &#39;unused beans&#39;</a></li>
  <li><a href="https://stackoverflow.com/questions/879965/how-to-detect-unused-properties-in-spring">How to detect unused properties in Spring</a></li>
  </ul>
  
  <p>However,</p>
  
  <ul>
  <li>I'm not interested in manually inspecting a graph or parsing log data.</li>
  <li>I don't have the added complexity of multiple context files, overriding beans, bean post-processing, or xml. It's a simple, straightforward, annotation-driven configuration.</li>
  <li>I'm using Spring Boot 1.2.6 which is several years newer than those questions (maybe new functionality exists).</li>
  </ul>
  
  <p>Spring will certainly throw an exception if a necessary bean is missing. Can it also throw an exception in the opposite scenario where a bean is found but unnecessary?</p>