title: How to have a Spring dynamic proxy with 2 interfaces?
body: <p>I have an object that is injected into my class by Spring (<a href="http://static.springsource.org/spring-batch/apidocs/org/springframework/batch/item/database/JdbcCursorItemReader.html" rel="nofollow">JdbcCursorItemReader</a> if you care).</p>
  
  <p>It implements 5 interfaces, two of which I care about (ItemReader, ItemStream). If I code my class to one or the other, the spring dynamic proxy gets properly injected and I can call methods on it</p>
  
  <pre><code>private ItemReader blah;
  public void setItemReader( blah ) { this.blah = blah };
  </code></pre>
  
  <p>Cool, that works as expected. I can also cast it to an ItemStream if I want to do something based on the ItemStream Interface:</p>
  
  <pre><code>((ItemStream))blah.close();
  </code></pre>
  
  <p>Cool, that lets me access methods of both classes. However, I am not a fan of casting, and know where has to be a better Spring Magic way to do it. The way I thought of was to make an Interface that combines both:</p>
  
  <pre><code>public interface IStreamingItemReader&lt;T&gt; extends ItemReader&lt;T&gt;, ItemStream {
  }
  </code></pre>
  
  <p>This lets my code use both... but the proxy injection predictably fails.</p>
  
  <blockquote>
    <p>Failed to convert property value of
    type [$Proxy0 implementing
    org.springframework.beans.factory.InitializingBean,org.springframework.batch.item.ItemReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised]
    to required type
    [blah.IStreamingItemReader] for
    property 'itemReader'; nested
    exception is
    java.lang.IllegalArgumentException:
    Cannot convert value of type [$Proxy0
    implementing
    org.springframework.beans.factory.InitializingBean,org.springframework.batch.item.ItemReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised]
    to required type
    [blah.IStreamingItemReader] for
    property 'itemReader': no matching
    editors or conversion strategy found</p>
  </blockquote>
  
  <p>The part that got my eye was
  <strong>no matching editors or conversion strategy found</strong></p>
  
  <p>Is there a way to teach Spring when it sees a <strong>JdbcCursorItemReader</strong>, to make a proxy of a <strong>IStreamingItemReader</strong>?  </p>
  
  <p>I realize I could fix this with CGLib and class based proxies... but if I could keep this as a dynamic interface proxy, I would be happier...</p>