1

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.

Community
  • 1
  • 1
swetha
  • 76
  • 1
  • 5

1 Answers1

0

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Thanks skaffman. This is an existing application and MessageSourceAccessor bean is being injected into bunch of different classes, and i dont feel comfortable changing all other classes. I'm wondering if there is any other work around for this problem. Please advise – swetha Nov 14 '11 at 17:59