Announcement Announcement Module
Collapse
No announcement yet.
Formal Unbound in Pointcut Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I gave you the code and everything you need, what do you want more?

    Comment


    • #17
      Can We Avoid JointPoint

      We'd rather not write the advice code if possible. I assume this would introduce an AspectJ dependency, which we'd like to avoid if possible, to keep the project as simple as we can.

      Can't we implement throws advice with ordinary Spring & not AspectJ? Can't we just change the XML somehow & not the advice code? We've been trying to follow the examples in Chapter 6 of the Spring reference manual, but so far it's been an exercise in frustration.

      Pardon my rant, but we're feeling very frustrated that a concept which seems so simple seems to be frighteningly complex.

      Comment


      • #18
        You already have a dependency on AspectJ (when using the aop:confgi stuff you already introduced that dependency). Next to that you use AspectJ pointcut expressions but don't want to use the rest.

        Code:
        <aop:config>
          <aop:pointcut id="allMethods" expression="execution(* *(..))" />
          <aop:advisor pointcut-ref="allMethods" advice-ref="throwsAdvice" />
        </aop:config>

        Comment


        • #19
          New Error - CGLIB

          Ok, I changed the config file to this:
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans 
             xmlns="http://www.springframework.org/schema/beans"
             xmlns:aop="http://www.springframework.org/schema/aop"
          	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          	xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
             "
             default-autowire="byName"
          >
             <bean id="maintenanceTransactionTypeDao" class="com.uprr.db.dao.spring.stats.MaintenanceTransactionTypeDAO" />
             <bean id="maintenanceItemTypeDao"        class="com.uprr.db.dao.spring.stats.MaintenanceItemTypeDAO"        />
             <bean id="maintenanceTransactionDao"     class="com.uprr.db.dao.spring.stats.MaintenanceTransactionDAO"     />
             <bean id="throwAdvice"                   class="com.uprr.aop.ThrowAdvice"                                   />
           
             <aop:config>
               <aop:pointcut id="allMethods" expression="execution(* *(..))" />
               <aop:advisor pointcut-ref="allMethods" advice-ref="throwAdvice" />
             </aop:config>
                 
          </beans>
          But now we get a different error:
          Code:
          Exception in thread "main" 2008-06-09 09:47:36,060 [main] DEBUG - Creating implicit proxy for bean 'maintenanceTransactionTypeDao' with 0 common interceptors and 2 specific interceptors
          2008-06-09 09:47:36,060 [main] INFO - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@62937c: defining beans [dataSource,propertyConfigurer,developmentDataSource,maintenanceTransactionTypeDao,maintenanceItemTypeDao,maintenanceTransactionDao,throwAdvice,org.springframework.aop.config.internalAutoProxyCreator,allMethods,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0]; root of factory hierarchy
          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'maintenanceTransactionTypeDao' defined in class path resource [spring-tns-api.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
          	at java.security.AccessController.doPrivileged(Native Method)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
          	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
          	at Test.main(Test.java:23)
          Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
          	at org.springframework.aop.framework.DefaultAopProxyFactory.createAopProxy(DefaultAopProxyFactory.java:67)
          	at org.springframework.aop.framework.ProxyCreatorSupport.createAopProxy(ProxyCreatorSupport.java:106)
          	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
          	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:473)
          	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:348)
          	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:309)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1342)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
          	... 14 more
          Google indicates "CGLIB" would require yet another jar in my classpath, which introduces even MORE complexity to the project. But the error message does mention an alternative of "proxy interfaces." How does one do proxy interfaces? What's the tradeoff between CGLIB & proxy interfaces? Is one significantly faster or easier to implement than the other?

          Comment


          • #20
            Advisor Not Called

            I went ahead & bit the bullet & put CGLIB in the CLASSPATH, then ASM when it said it needed that, too. The app now runs to completion, except that the ThrowsAdvice is not executed, even after the code deliberately throws an exception to test it. Here's the log output (or as much as the forum software would accept). Can anyone see why the throws advisor is not called?

            Code:
            [org.springframework.context.support.ClassPathXmlApplicationContext@edf730]; startup date [Mon Jun 09 11:16:42 CDT 2008]; root of context hierarchy]
            2008-06-09 11:16:47,200 [main] DEBUG - Returning cached instance of singleton bean 'maintenanceTransactionTypeDao'
            2008-06-09 11:16:47,216 [main] DEBUG - Found exception handler method: public void com.uprr.aop.ThrowAdvice.afterThrowing(java.lang.reflect.Method,java.lang.Object[],java.lang.Object,java.lang.Throwable)
            2008-06-09 11:16:47,294 [main] DEBUG - Executing SQL query [SELECT * FROM ctxd222.efm_ntwk_mtce_tran_types ORDER BY sort_ord_seq]
            2008-06-09 11:16:47,325 [main] DEBUG - Fetching JDBC Connection from DataSource
            2008-06-09 11:16:47,325 [main] DEBUG - Found exception handler method: public void com.uprr.aop.ThrowAdvice.afterThrowing(java.lang.reflect.Method,java.lang.Object[],java.lang.Object,java.lang.Throwable)
            2008-06-09 11:16:47,325 [main] DEBUG - Found exception handler method: public void com.uprr.aop.ThrowAdvice.afterThrowing(java.lang.reflect.Method,java.lang.Object[],java.lang.Object,java.lang.Throwable)
            2008-06-09 11:16:47,341 [main] DEBUG - Creating new JDBC Connection to [jdbc:oracle:thin:@dev091.oracle.uprr.com:1521:dev091]
            2008-06-09 11:16:48,185 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Falling back to [java.util.LinkedHashMap] for linked case-insensitive map
            2008-06-09 11:16:48,216 [main] DEBUG - Returning JDBC Connection to DataSource
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=1,desc=Create Track]
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=2,desc=Modify Track]
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=3,desc=Delete Track]
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=4,desc=Remilepost Track]
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=5,desc=Split Track]
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=6,desc=Connect Tracks]
            2008-06-09 11:16:48,232 [main] INFO - TRAN_TYPE[sys#=7,desc=Disconnect Tracks]
            2008-06-09 11:16:48,232 [main] DEBUG - Found exception handler method: public void com.uprr.aop.ThrowAdvice.afterThrowing(java.lang.reflect.Method,java.lang.Object[],java.lang.Object,java.lang.Throwable)
            2008-06-09 11:16:48,232 [main] DEBUG - Executing SQL query [SELECT tran_desc FROM ctxd222.efm_ntwk_mtce_tran_types WHERE tran_type_sys_nbr = 3]
            2008-06-09 11:16:48,232 [main] DEBUG - Fetching JDBC Connection from DataSource
            2008-06-09 11:16:48,232 [main] DEBUG - Creating new JDBC Connection to [jdbc:oracle:thin:@dev091.oracle.uprr.com:1521:dev091]
            2008-06-09 11:16:48,560 [main] DEBUG - Returning JDBC Connection to DataSource
            2008-06-09 11:16:48,591 [main] INFO - Transaction type # 3 = Delete Track
            Exception in thread "main" java.lang.Exception: Dummy exception to test AOP
            	at Test.testItemTypes(Test.java:32)
            	at Test.main(Test.java:26)

            Comment


            • #21
              Closed

              I'm going to close this and open a separate thread, since the focus of the problem has changed. Now the issue is just down to why the advisor isn't being called.

              Comment


              • #22
                Google indicates "CGLIB" would require yet another jar in my classpath, which introduces even MORE complexity to the project. But the error message does mention an alternative of "proxy interfaces." How does one do proxy interfaces? What's the tradeoff between CGLIB & proxy interfaces? Is one significantly faster or easier to implement than the other?
                You should be programming to interfaces however you probably aren't doing that. So you need to use class proxying. (Which is also what your stacktrace indicates).

                Comment

                Working...
                X