Spring AOP - 生成代理时出错

发布于 2024-12-15 01:53:01 字数 1039 浏览 0 评论 0原文

我正在使用 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

我在 线程。但我无法更改 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>

如果有人可以提供帮助,我将非常感激。感谢您抽出时间。

I'm using spring AOP's around advice to capture processing time of a transaction. I'm getting the following error during application startup

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

I identified what the problem is with the help of this thread. But I cannot change coreMessageResourceAccesor bean to use setter based injection because its using a spring class & that class doesn't have no arg constructor

Below is the configuration for the bean

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

I would really appreciate if someone could help. Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-12-22 01:53:01

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

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

You don't need really need to configure MessageSourceAccessor accessor as a bean, it's generally easier to instantiate it manually as required. So rather than inject the MessageSourceAccessor into your beans, inject the raw MessageSource, and then wrap it in a MessageSourceAccessor as required (i.e. using new MessageSourceAccessor(messageSource)).

You can then put the advice around the MessageSource rather than the MessageSourceAccessor, which will work better. Also, MessageSourceAccessor will not itself add any significant processing time, it's just a thin wrapper around MessageSource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文