Announcement Announcement Module
Collapse
No announcement yet.
FactoryBeanNotInitializedException encountered when using AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FactoryBeanNotInitializedException encountered when using AOP

    Hello AOP forum:

    I got the basic mechanics of AOP working, using a very useful article at http://javaboutique.internet.com/tutorials/ehcache/

    and my config is:

    <aop:config>
    <aopointcut id="processAddProgramPointcut" expression="execution(* *..ProgramMgrImp.processAddProgram(..))" />
    <aop:advisor id="methodTimingAdvisor" advice-ref="methodTimingAdvice" pointcut-ref="processAddProgramPointcut" />
    </aop:config>

    <bean id="methodTimingAdvice" class="gov.nih.nci.rtips.biz.aop.TimingLoggingInte rceptor" />


    The problem is that when I want to put some useful code in my advice which uses another bean in our project, like so...

    <bean id="methodTimingAdvice" class="gov.nih.nci.rtips.biz.aop.TimingLoggingInte rceptor">
    <property name="programMgr"><ref bean="programMgr"/></property>
    </bean>

    ... Tomcat now throws an exception:

    ================================================== =====
    ERROR [ContextLoader.java : 205] Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataMgrTarget' defined in ServletContext resource [/WEB-INF/rtipsContext
    .xml]: Cannot resolve reference to bean 'programMgr' while setting bean property 'programMgr'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'programMgr' defined in ServletContext resource [/WEB-INF/rtipsContext.xml]: Cannot resolve reference to bean 'programMgrTarget' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'methodTimingAdvice' defined in ServletContext resource [/WEB-INF/rtipsContext.xml]:
    Cannot resolve reference to bean 'programMgr' while setting bean property 'programMgr'; nested exception is org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'programMgr': org.springframework.beans.factory.FactoryBeanNotIn itializedException: FactoryBean is not fully initialized yet
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver
    .resolveReference(BeanDefinitionValueResolver.java :253) [spring.jar:2.0.2]
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver
    .resolveValueIfNecessary(BeanDefinitionValueResolv er.java:124) [spring.jar:2.0.2]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.applyPropertyValues(AbstractAutowireCapabl eBeanFactory.java:1019) [spring.jar:2.0.2]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    ================================================== ====


    Viewing FactoryBeanNotInitializedException on SpringSource (http://static.springsource.org/sprin...Exception.html), it says something about circular references/beans being accessed before being fully initialized.


    Has anyone encountered this, or can you point me in a direction?

    Thank you in advance.

    --Harvey

  • #2
    Why are you injecting a bean that you are advising in the advisor? You have program mgr which you are advising with TimingLoggingInterceptor. Why are you injecting that bean in the advisor?

    Comment


    • #3
      Thank you for responding.

      The reason is that the advice (methodTimingAdvice) calls a method in ProgramMgr which repopulates the Programs in the cache. Is that not allowed?

      In any case, this method is not called during context initialization, so even it is a problem, I would have thought it would be encountered only when the method was called. Is that not correct?

      Comment


      • #4
        Originally posted by hflaisher View Post
        Thank you for responding.

        The reason is that the advice (methodTimingAdvice) calls a method in ProgramMgr which repopulates the Programs in the cache. Is that not allowed?

        In any case, this method is not called during context initialization, so even it is a problem, I would have thought it would be encountered only when the method was called. Is that not correct?
        So your method timing advice has cache re-population logic? Does not seem like a good design...

        At any rate, the reason you are getting this error in general is that your manager is not completely created until the advice is applied. The advisor is injecting the bean that is proxying. So you are getting bean in creation error because the bean is still being created and cannot be injected until it is but it can't be since it's advisor has dependency on it. Hence the circular reference...

        Comment


        • #5
          thanks, I think I understand that, but a final question, how then should this be designed?

          I can pull the method that refreshes the cache out of ProgramMgr to decouple it from ProgramMgr, but the new class to which it will belong will then still have the dependency upon ProgramMgr, since all methods which access programs logically belong in ProgramMgr. So I would then have:

          <!-- dependency on ProgramMgr removed -->
          <bean id="methodTimingAdvice" class="gov.nih.nci.rtips.biz.aop.TimingLoggingInte rceptor">
          <property name="programMgr"><ref bean="newClass"/></property>
          </bean>

          <!-- .. but added back in here... -->
          <bean id="newClassId" class="gov.nih.nci.rtips.biz.aop.newClass">
          <property name="programMgr"><ref bean="programMgr"/></property>
          </bean>

          Do I need to pull all dependent methods out of ProgramMgr into a new class of their own?

          thanks very much for your advice.

          --Harvey

          PS - regarding your first point, the advice is dedicated to caching, it just needs to be renamed to reflect that.

          Comment


          • #6
            can you post all your code so we can get a little more context? I don't want to tell you something to mess up your design, from what you posted it looked as if something wasn't jiving (in addition to circular dependencies). overall, yes, if you pull out your cache refresh code to another place it'll work... but this also makes me wonder why are you implementing your own caching??! and refreshing?!

            Comment

            Working...
            X