简体   繁体   English

Spring AOP中的NamedParameterJdbcTemplate和CGlib

[英]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.

相关问题 Spring AOP CGLIB 代理的字段为空 - Spring AOP CGLIB proxy's field is null Spring AOP:确认CGLIB代理行为 - Spring AOP: confirming CGLIB proxy behaviour 同一类调用在Spring AOP cglib中无效 - Same class invoke NOT effective in Spring AOP cglib Spring AOP 什么时候使用 CGLIB 代理? - When is CGLIB proxy used by Spring AOP? Spring AOP,Cglib增强类丢失通用信息 - Spring aop, cglib enhanced class lose generic info Spring AOP:AopConfigException:无法生成类的CGLIB子类 - Spring AOP: AopConfigException: Could not generate CGLIB subclass of class Spring AOP和最终类抛出“无法生成CGLIB子类”的问题 - Issue with Spring AOP and Final class throwing “Could not generate CGLIB subclass” 使用CGLIB / Spring AOP时如何防止误报空指针警告? - How to prevent false positive null pointer warnings, when using CGLIB / Spring AOP? Spring AOP错误:java.lang.NoClassDefFoundError:org / springframework / cglib / core / SpringNamingPolicy - Spring AOP Error : java.lang.NoClassDefFoundError: org/springframework/cglib/core/SpringNamingPolicy Spring AOP - Jboss:无法生成类 org.jboss.as.connector.subsystems.datasources.WildFlyDataSource 的 CGLIB 子类 - Spring AOP - Jboss : Could not generate CGLIB subclass of class org.jboss.as.connector.subsystems.datasources.WildFlyDataSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM