NamedParameterJdbcTemplate and CGlib in Spring AOP

546 views Asked by At

Hi All in my Spring application i have used AutoWired NamedParameterJdbcTemplate.

@Autowired
    NamedParameterJdbcTemplate namedParametersJdbcTemplate;

in my rest-servlet.xml

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/mylfrdb"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg ref="dataSource"/>
    </bean>
 <bean class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" id="namedParameterJdbcTemplate">  
   <constructor-arg ref="jdbcTemplate"></constructor-arg> 

</bean> 

<bean class="org.springframework.jdbc.core.simple.SimpleJdbcCall" id="simpleJdbcCall">  
   <constructor-arg ref="dataSource"></constructor-arg>
</bean>

It working fine. No i have to use performance intercepter with Spring AOP.

So i added following thing in my rest-servlet.xml

<aop:config >

<aop:pointcut expression="@target(org.springframework.stereotype.Service)" id="allServices"/>

<aop:advisor pointcut-ref="allServices" advice-ref="perfMonitor"/>


</aop:config>

So i got error like this. Can not set org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate field com.lfr.dao.impl.FlatAdvertiseDaoImpl.namedParametersJdbcTemplate to com.sun.proxy.$Proxy15

So i refered this question and tried to implement 2nd solution give is by using CGLIB and

<aop:config proxy-target-class="true" >

No i am getting this error

Could not generate CGLIB subclass of class [class org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given

1

There are 1 answers

1
Joosep Simm On BEST ANSWER

I had the exact same error message. I was using Spring 3.2.5.RELEASE version. After debugging and trying to repeat the problem with PetClinic example came out it was matter of Spring version. This problem didn't occur in Spring 4.1.1. Try to upgrade, maybe it works.