Note that there are some explanatory texts on larger screens.

plurals
  1. POThe Spring AOP Proxy that isn't
    primarykey
    data
    text
    <p>I have two Spring proxies set up:</p> <pre><code> &lt;bean id="simpleBean" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;property name="target"&gt; &lt;ref local="simpleBeanTarget"/&gt; &lt;/property&gt; &lt;property name="interceptorNames"&gt; &lt;list&gt; &lt;value&gt;cacheInterceptor&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="springDao" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;property name="target" ref="springDaoTarget"/&gt; &lt;property name="interceptorNames"&gt; &lt;list&gt; &lt;value&gt;daoInterceptor&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>simpleBean works just fine -- springDao does not.</p> <p>The SpringDao class looks like:</p> <pre><code>public class SpringDao extends JdbcDaoSupport { private SimpleJdbcTemplate simpleJdbcTemplate; public SimpleJdbcTemplate getSimpleJdbcTemplate() { if (simpleJdbcTemplate==null) { simpleJdbcTemplate= new SimpleJdbcTemplate(getDataSource()); } return simpleJdbcTemplate; } ... </code></pre> <p>And I have my unit test autowired like this:</p> <pre><code>@Autowired @Qualifier("springDao") protected SpringDao springDao; </code></pre> <p>And the first indication something is wrong is I get this error:</p> <blockquote> <p>Could not autowire field: . . . nested exception is java.lang.IllegalArgumentException</p> </blockquote> <p>If I comment out the @Qualifier annotation and run my unit test again, I get this:</p> <blockquote> <p>No unique bean of type ... expected single matching bean but found 2: [springDaoTarget, springDao]</p> </blockquote> <p>That is what I expected.</p> <p>So I changed my autowiring to </p> <pre><code>@Autowired @Qualifier("springDaoTarget") protected SpringCustomerCapacityDao springDao; </code></pre> <p>And added the following to my unit test:</p> <pre><code> Object proxy = applicationContext.getBean("springDao"); Assert.assertNotNull(proxy); Assert.assertTrue(proxy instanceof SpringDao); </code></pre> <p>And the instanceof test failed, which (to me) means that my proxy is not really my proxy.</p> <p>So I'm confused. What's going on? How can I fix this?</p> <p><strong>Edit</strong> Here is the requested springDaoTarget definition, which will disappoint many people:</p> <pre><code>&lt;bean id="springDaoTarget" class="com.company.SpringDao"&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload