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

  • Bean creation failing once aop:config is added

    Hi,

    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):

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

    Code:
    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,
    Chris

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

    Comment


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

      Code:
      <bean id="mrzDispatcher" class="LegacyMRZDispatcher">
          <constructor-arg index="0" ref="bean1" />
          <constructor-arg index="1" ref="bean2" />
          <constructor-arg index="2">
              <props>
                  <prop key="blah">blah</prop>
                  ... 5 more properties
              </props>
          </constructor-arg>
          <constructor-arg index="3" ref="bean3" />
          <constructor-arg index="4" ref="bean4" />
      </bean>
      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.

      Code:
      ApplicationContext ctx = new ClassPathXmlApplicationContext(file);
      
      Bean1 bean1 = (Bean1) ctx.getBean("bean1");
      etc
      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):

      Code:
      <beans xmlns="http://www.springframework.org/schema/beans"
      	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	   xmlns:aop="http://www.springframework.org/schema/aop"
      	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
      						   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
      Last edited by Gentleman Hal; Jul 26th, 2007, 06:14 AM. Reason: Forgot to mention something

      Comment


      • #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.

        Comment


        • #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!

          Comment


          • #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.

            Code:
            INFO <org.springframework.beans.factory.support.DefaultLi
            stableBeanFactory> Destroying singletons in org.springframework.beans.factory.support.DefaultListableBean
            Factory@c4aad3: 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).

            Comment

            Working...
            X