【问题标题】:NamedParameterJdbcTemplate and CGlib in Spring AOPSpring AOP 中的 NamedParameterJdbcTemplate 和 CGlib
【发布时间】:2015-01-19 10:56:47
【问题描述】:

大家好,在我的 Spring 应用程序中,我使用了 AutoWired NamedParameterJdbcTemplate。

@Autowired
    NamedParameterJdbcTemplate namedParametersJdbcTemplate;

在我的 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>

它工作正常。 不,我必须在 Spring AOP 中使用性能拦截器。

所以我在我的 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>

所以我得到了这样的错误。 无法将 org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate 字段 com.lfr.dao.impl.FlatAdvertiseDaoImpl.namedParametersJdbcTemplate 设置为 com.sun.proxy.$Proxy15

所以我参考了这个问题并尝试实施第二个解决方案,即使用 CGLIB 和

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

不,我收到此错误

无法生成类 [class org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate] 的 CGLIB 子类:此问题的常见原因包括使用最终类或不可见类;嵌套异常是 java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments are given

【问题讨论】:

    标签: java spring spring-mvc spring-aop cglib


    【解决方案1】:

    我收到了完全相同的错误消息。我使用的是 Spring 3.2.5.RELEASE 版本。在调试并尝试用 PetClinic 示例重复问题后,出现了 Spring 版本的问题。这个问题在 Spring 4.1.1 中没有出现。尝试升级,也许可以。

    【讨论】:

    • 是的,它是 spring 3.0
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多