Spring AOP - 生成代理时出错
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您并不需要真正将
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 theMessageSourceAccessor
into your beans, inject the rawMessageSource
, and then wrap it in aMessageSourceAccessor
as required (i.e. usingnew MessageSourceAccessor(messageSource)
).You can then put the advice around the
MessageSource
rather than theMessageSourceAccessor
, which will work better. Also,MessageSourceAccessor
will not itself add any significant processing time, it's just a thin wrapper aroundMessageSource
.