title: Check, if a scoped bean is null
body: <p>In my Java-Configuration in Spring I have a bean, that is annotated as follows:</p>
  
  <pre><code>@Bean
  @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
  public Object foo() { ... }
  </code></pre>
  
  <p>This method sometimes returns a null (if there is nothing to instanciate). In my code, I would like to check for this case like:</p>
  
  <pre><code>@Inject
  Object foo
  
  if (foo != null)
     foo.be_wise();
  </code></pre>
  
  <p>But this does not work, because foo is proxied and, hence, is never null! So, the only way to check for the null I could find is to trigger the NullPointerException like this:</p>
  
  <pre><code>try
  {
    foo.dont_be_wise();
  }
  catch (NullPointerException e)
  {
    be_wise();
  }
  </code></pre>
  
  <p>I do not like that, because throwing exceptions is costly!</p>
  
  <p>Is there another way to check the proxied bean for null?</p>