【问题标题】:Spring AOP - Error Generating proxiesSpring AOP - 错误生成代理
【发布时间】:2011-11-15 04:53:30
【问题描述】:

我正在使用 spring AOP 的环绕建议来捕获事务的处理时间。我在应用程序启动期间收到以下错误

error creating bean "coreMessageResourceAccesor"
   Could not generate CGLIB subclass of class 
     [class org.springframework.context.support.MessageSourceAccessor]: 
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

thread 的帮助下,我确定了问题所在。但是我不能将 coreMessageResourceAccesor bean 更改为使用基于 setter 的注入,因为它使用 spring 类并且该类没有 arg 构造函数

下面是bean的配置

<bean id="coreMessageSourceAccessor"
        class="org.springframework.context.support.MessageSourceAccessor" >
    <constructor-arg type="org.springframework.context.MessageSource"
        ref="coreMessageSource" />
</bean>

如果有人可以提供帮助,我将不胜感激。感谢您的宝贵时间。

【问题讨论】:

    标签: spring aop spring-aop cglib


    【解决方案1】:

    您实际上不需要将MessageSourceAccessor 访问器配置为bean,根据需要手动实例化它通常更容易。因此,与其将MessageSourceAccessor 注入您的bean,不如注入原始MessageSource,然后根据需要将其包装在MessageSourceAccessor 中(即使用new MessageSourceAccessor(messageSource))。

    然后,您可以将建议放在MessageSource 而不是MessageSourceAccessor 周围,这样会更好。此外,MessageSourceAccessor 本身不会增加任何显着的处理时间,它只是 MessageSource 的一个薄包装。

    【讨论】:

    • 谢谢斯卡夫曼。这是一个现有的应用程序,MessageSourceAccessor bean 被注入到一堆不同的类中,我对更改所有其他类感到不舒服。我想知道这个问题是否还有其他解决方法。请指教
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 2012-01-03
    • 2018-07-07
    • 1970-01-01
    相关资源
    最近更新 更多