Announcement Announcement Module
Collapse
No announcement yet.
AOP with Groovy beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by cltam96 View Post
    Dear All

    Juergen Hoeller has already fixed the AOP and Groovy bean problem. The fix will be available in the next snapshot of spring 2.0.3. The current snapshot build.121-20070301 does not contain the fix. Janos problem should be solved with the fix. Please refer to the following link about the problem and fix:
    AspectJExpressionPointcut throws ReflectionWorldException. Thanks for Juergen help.

    cheers
    chris tam
    xenium
    Chris,

    I am facing same problem applying AOP to groovy bean.
    I have downloaded spring 2.0.3. But still problem has not gone.

    Could you please tell which version of spring build should i use to rectify this problem.

    TIA,
    Shiv

    Comment


    • #17
      Dear Shiv

      The fix is included in the official release of spring 2.0.3. You can download the spring 2.0.3 release and test. If your problem still exists, please post the error messages. Thanks.

      cheers
      chris tam
      xenium

      Comment


      • #18
        Workaround

        You can create a AppContext with the GroovyClassloader as default Classloader


        private GenericApplicationContext createAppContext(String path) {
        GenericApplicationContext ctx = new GenericApplicationContext();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);

        defaultClassLoader = new GroovyClassLoader(this.getClass().getClassLoader() );
        reader.setBeanClassLoader(defaultClassLoader);
        reader.loadBeanDefinitions(path);
        ctx.refresh();
        return ctx;
        }
        After that you can create Beans in Groovy and define them in your beans.xml like they where written in Java.

        beans.xml
        ...
        <bean id="tm" class="de.sdm.flextest.ticketing.bo.impl.TicketMan agerImpl"/>
        ...
        de/sdm/flextest/ticketing/bo/impl/TicketAssemblerImpl.groovy
        class TicketAssemblerImpl extends AbstractAssembler implements IBaseAssembler {

        ITicketManager ticketManager;
        IUserNameManager userNameManager;
        IFlexTransactionManager transactionManager;

        ....
        }
        With this approch AOP works fine in my case.

        -- Spiral

        Comment


        • #19
          But you don't need the workaround. The issue has been fixed in the current 2.0 release.

          Also your method wouldn't handle recompilation of dependent references held by long lived singletons. (ie. service bean A has a reference to DAO B. You change DAO B's groovy source. Because A is a singleton it will still have the old version of B wired into it. Spring's proxied Groovy beans fixes this.)

          Mark

          Comment


          • #20
            I'm using spring 2.5.6, but am seeing this issue still I think, but in the following way:

            Code:
            Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine annotations of missing type groovy.DefaultPasswordControl
             [Xlint:cantFindType]
            	at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:163)
            	at org.aspectj.weaver.Lint$Kind.signal(Lint.java:293)
            	at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:198)
            	at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.hasAnnotation(MissingResolvedTypeWithKnownSignature.java:152)
            	at org.aspectj.weaver.patterns.ExactAnnotationTypePattern.fastMatches(ExactAnnotationTypePattern.java:65)
            	at org.aspectj.weaver.patterns.WithinAnnotationPointcut.fastMatch(WithinAnnotationPointcut.java:82)
            	at org.aspectj.weaver.patterns.AndPointcut.fastMatch(AndPointcut.java:48)
            	at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.couldMatchJoinPointsInType(PointcutExpressionImpl.java:78)
            	at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:235)
            	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:195)
            	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:250)
            	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:284)
            	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:113)
            	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:85)
            	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)
            	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362)
            	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:325)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:764)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:399)
            	... 93 more
            It seems as though the aspectj classloader can't find the groovy bean, which happens when I get a reference to the bean in question.

            I have derived a class from ScriptFactoryPostProcessor that allows me to load the script from a db, and my overridden class just returns my version of an implementation of ScriptSource that does the work necessary to get the script.

            <bean id="scriptFactoryPostProcessor" class="com.opterus.opscenter.shared.script.CustomS criptFactoryPostProcessor">
            <!-- <property name="scriptExtensionFacade">
            <ref bean="cacheScriptExtensionFacade" />
            </property> -->
            </bean>

            <lang:defaults refresh-check-delay="1200000"/>
            <lang:groovy id="passwordControl" scope="request" script-source="db:groovy/PasswordControl.groovy"/>

            If I define this post processor bean before the lang:groovy bean definition, the above error occurs. If I put the beans the other way around, a different error occurs.

            Any help would be appreciated!
            Last edited by ianlong; Feb 25th, 2009, 01:18 PM.

            Comment

            Working...
            X