Announcement Announcement Module
No announcement yet.
aspect getting executed multiple times Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • aspect getting executed multiple times


    aop.xml has configuration for aspects <aop:config>.

    The final.xml is getting aop.xml imported many times because of intermediate configuration files. But, when application context is loaded with final.xml, the aspect defined in aop.xml is executed multiple times.

    Is it because the aop.xml which has aop configuration is getting loaded multiple times?How do we avoid aspect getting executed multiple times?

    I am using spring 2.5


  • #2
    Yes, every time that an <aop:aspect> is parsed by AopNamespaceHandler a new root advice bean is registered with name AspectJPointcutAdvisor#N with N = 0, 1, 2, 3 ...


    • #3
      Thanks for replying. Is there any way to avoid this apart from making sure loading the aspect only once?


      • #4
        As far as i known, no in framework itself, you can extends or decorate ConfigBeanDefinitionParser.parse() to make it aware of already parsed advices but, ¿Why to do it?,. seems not very useful loading an aop configuration twice.


        • #5
          In our design, the aop configuration aop-config.xml is placed at framework/common project. All other projects import it.

          project-a config file imports aop-config.xml
          project-b config file imports aop-config.xml
          project-c config file imports aop-config.xml

          Now, project-c config imports project-a config file, then aop-config.xml is getting loaded twice in DI container. It is common in our application. Do you think we should have some mechanism to laod aop-config.xml only once... If there is no out-of-box solution to avoid this in spring framework....


          • #6
            Well, I never use import and set all config locations in the applicationContext itself. This will solve your problem.

            Spring don't have a #pragma-one or include-guard like mechanism. To add it you can override DefaultBeanDefinitionDocumentReader.importBeanDefi nitionResource() and call super() only on not already imported resources.


            • #7
              The most important thing in life is taking responsibility for your own outcomes. Good or bad. So many of us want to take credit for the good, but shove the responsibility for the bad stuff off ono someone or something else.

              free video converter|download full version|free downloads