Announcement Announcement Module
No announcement yet.
Bean creation failing once aop:config is added Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean creation failing once aop:config is added


    I'm trying to add some Spring AOP configuration to our application to aid error reporting. So I added the following to the Spring configuration file (slightly edited for clarity):

        <aop:aspect id="errorReporter" ref="err">
            <aop:after-throwing pointcut="execution(* *(..)) and not target(ErrorReporter)" 
                                method="reportError" />
    <bean id="err" class="ErrorReporter" />
    But as soon as this is added another Bean fails to be created.

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mrzDispatcher' de
    fined in class path resource [spring-config-business.xml]: 5 constructor arguments specified but no match
    ing constructor found in bean 'mrzDispatcher' (hint: specify index and/or type arguments for simple param
    eters to avoid type ambiguities)
    The constructor certainly exists and as soon as the AOP configuration is removed the Bean is created fine once more. I'm completely new to AOP so maybe I'm doing something horribly wrong but I can't work out why this particular error should be happening.

    Does anyone know why this is happening and how to fix it?

    If need any more information just let me know.

    Thanks in advance,

  • #2
    Can you post, please, a more complete configuration ? (including definition of mrzDispatcher). And, also, how do you instantiate your application context ?


    • #3
      The rest of the configuration file is just plain uninteresting Bean definitions.

      <bean id="mrzDispatcher" class="LegacyMRZDispatcher">
          <constructor-arg index="0" ref="bean1" />
          <constructor-arg index="1" ref="bean2" />
          <constructor-arg index="2">
                  <prop key="blah">blah</prop>
                  ... 5 more properties
          <constructor-arg index="3" ref="bean3" />
          <constructor-arg index="4" ref="bean4" />
      again I've edited it for clarity and the fact this code is for work so I'm not sure how much I can post unedited.

      Assuming I understand 'instantiate your application context' correctly, this is part of a stand alone application so I manually instantiate it in the main method.

      ApplicationContext ctx = new ClassPathXmlApplicationContext(file);
      Bean1 bean1 = (Bean1) ctx.getBean("bean1");
      Sorry if this hasn't given you any more insight into my problem

      Edit: I have the aop namespace defined as follows (just incase that's wrong):

      <beans xmlns=""
      Last edited by Gentleman Hal; Jul 26th, 2007, 05:14 AM. Reason: Forgot to mention something


      • #4
        I tried to reproduce your error with no luck. I used an after-throwing advice and a match-able bean with constructor DI.
        Try creating a test case with classes outside your project.


        • #5
          Thats for taking the time to try and reproduce my problem. I'll do as you suggest as soon as I can and let you know!


          • #6
            Ok, I'm also unable to reproduce the problem with a test case.

            However I have noticed that right before the error is thrown in my real application I get an Info log message telling me it's destroying singletons, which doesn't happen when the AOP stuff is removed. I doubt this helps any but I thought I'd mention it just in case.

            INFO <
            stableBeanFactory> Destroying singletons in
            [email protected]: defining beans [My Beans listed here]; root of factory hierarchy
            Anyway I'll keep trying to see if I can reproduce this problem with a simple test case.

            One final thing one of the beans I'm creating (not the mrzDispatcher though) uses an instance of a class which has native methods (and loads some native libraries in a static block). This class however is actually excluded from the pointcut, so I wouldn't assume it was causing problems... (yeah, I'm really clutching at straws here).