[英]NamedParameterJdbcTemplate and CGlib in Spring AOP
Hi All in my Spring application i have used AutoWired NamedParameterJdbcTemplate. 大家好,我在Spring应用程序中使用了AutoWired NamedParameterJdbcTemplate。
@Autowired
NamedParameterJdbcTemplate namedParametersJdbcTemplate;
in my rest-servlet.xml 在我的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.
不,我必须在Spring AOP中使用性能拦截器。
So i added following thing in my rest-servlet.xml 所以我在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
无法将org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate字段com.lfr.dao.impl.FlatAdvertiseDaoImpl.namedParametersJdbcTemplate设置为com.sun.proxy。$ Proxy15
So i refered this question and tried to implement 2nd solution give is by using CGLIB and 所以我提到了这个问题,并试图通过使用CGLIB来实现第二个解决方案
<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; 无法生成类[类org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate]的CGLIB子类。 nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
嵌套异常是java.lang.IllegalArgumentException:超类没有null构造函数,但未提供任何参数
I had the exact same error message. 我有完全相同的错误消息。 I was using Spring 3.2.5.RELEASE version.
我正在使用Spring 3.2.5.RELEASE版本。 After debugging and trying to repeat the problem with PetClinic example came out it was matter of Spring version.
经过调试并尝试用PetClinic示例重现该问题,这是Spring版本的问题。 This problem didn't occur in Spring 4.1.1.
在Spring 4.1.1中没有发生此问题。 Try to upgrade, maybe it works.
尝试升级,也许可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.