Announcement Announcement Module
Collapse
No announcement yet.
Can a pointcut refer to classes inside a JAR? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can a pointcut refer to classes inside a JAR?

    Hi,

    i'm using declaritive transaction management. i have a jar-file that contains the service-objects which in turn persist my domain-objects with the help of daos. now i want to add transaction management with aop-proxies like this:

    Code:
    	<aop:config>
    		<aop:pointcut id="managerMethod" expression="execution(* components.impl.*Manager.*(..))"/> 
    		<aop:advisor advice-ref="txAdvice" pointcut-ref="managerMethod"/>
    	</aop:config>
    components.impl... is inside a JAR-file. should this work?

    regards

  • #2
    Originally posted by garz View Post
    Hi,

    i'm using declaritive transaction management. i have a jar-file that contains the service-objects which in turn persist my domain-objects with the help of daos. now i want to add transaction management with aop-proxies like this:

    Code:
    	<aop:config>
    		<aop:pointcut id="managerMethod" expression="execution(* components.impl.*Manager.*(..))"/> 
    		<aop:advisor advice-ref="txAdvice" pointcut-ref="managerMethod"/>
    	</aop:config>
    components.impl... is inside a JAR-file. should this work?

    regards
    That depends on the algorithm used by the class loader(s) that loads spring and application classes and deployment unit organization. Feel free to read more about that at the reference - 5.7. Application contexts and Resource paths. The forum also has a lot of posts about that. The most recent post as I remember is Problem getting @Transaction annotations injected .

    Comment


    • #3
      hey denis,

      thx for your reply! i'm very happy.

      ok what you say is that this should work, but i don't really understand what this has to do with the classloader and how i'm able to influence what the classloader does. i've read the advised part of the reference numerous times and really cant even imagine the slightest what this has to do with my problem. you see my overall understanding is not good engough.

      the proposed solution in the thread doesnt work for me. i dont export any war-archives or similar, i'm using the glassfish plugin which does the deploying.

      you say there are numerous threads about this problem already in the forum. can you plz tell me the keywords i have to search for?

      btw the funny thing is, i already stumbled upon the thread you posted before i created my own thread and i didnt even realize that it holds a solution to my problem. but i now think that he had a different kind of problem. his problem was, that the spring-library wasnt included in his war-archive. this is not the problem with me, i already tested the aspect and it worked. i think the problem is, that the advised class in inside a jar file. btw i cant search for jar because the word is too short...

      best regards and thx again for your help.

      Comment


      • #4
        Am I right assuming that
        1. Your spring container contains definitions for the beans which bytecode is packed to the jar;
        2. There is an aop setup within the container;
        3. Aspects are not applied for those beans;
        ?

        I.e. spring container correctly instantiates the beans but aop logic is not applied to them?

        (If my vision of the problem is correct, I was wrong mentioning classloaders at the first reply )

        Comment


        • #5
          Originally posted by denis.zhdanov View Post
          Am I right assuming that
          1. Your spring container contains definitions for the beans which bytecode is packed to the jar;
          2. There is an aop setup within the container;
          3. Aspects are not applied for those beans;
          ?

          I.e. spring container correctly instantiates the beans but aop logic is not applied to them?
          yes thats totally right. i'm already using the manager class and when i call a method on it it fails because hibernate is involved and that doesnt work without a transaction. here is a snippet of my applicationContext.xml:

          Code:
          <bean id="simpleManager" class="components.impl.SimpleManager"/>
          
          <bean id="hbmTxManager" class="org.springframework.transaction.jta.JtaTransactionManager"/> 
          	
          <tx:advice id="txAdvice" transaction-manager="hbmTxManager">
          	<tx:attributes>
          		<tx:method name="read" read-only="true"/>
          		<tx:method name="readAll" read-only="true"/>
          		<tx:method name="*"/> 
          	</tx:attributes>
          </tx:advice>
          	
          <aop:config>
          	<aop:pointcut id="managerMethod" expression="execution(* components.impl.*Manager.*(..))"/> 
          	<aop:advisor advice-ref="txAdvice" pointcut-ref="managerMethod"/> 
          </aop:config>
          maybe the expression is wrong? but i copied and pasted the path, so that there cant be a fault. i could debug if i knew the class that evaluates the aop:config-tags. do you know it?

          Comment


          • #6
            How 'components.impl.*Manager' methods are called? Are you sure there are no self-calls?

            Comment


            • #7
              my context.xml is like this
              <?xml version="1.0" encoding="UTF-8"?>
              <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"
              xmlns:context="http://www.springframework.org/schema/context"
              xmlns:tx="http://www.springframework.org/schema/tx"
              xsi:schemaLocation="
              http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd
              http://www.springframework.org/schema/aop http://www.springframework.org/schem...spring-aop.xsd
              http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
              <bean id="test" class="com.TestBean"/>
              <bean class="com.TestAop"></bean>
              <bean class="com.LoggingAspectPC">
              <property name="beforeMessage" value="Before"/>
              <property name="afterMessage" value="After"/>
              </bean>
              <context:spring-configured />
              <context:annotation-config/>
              <aop:aspectj-autoproxy />
              <!-- <context:load-time-weaver/>-->
              </beans>


              and i want to pointcut expression is given below

              @Around("execution(* java.io.PrintStream.*(..)) && !within(com.TestAop.*)")
              public void sysTest(ProceedingJoinPoint pjp) throws Throwable
              {
              System.out.println("in stsTest ");
              pjp.proceed();
              System.out.println("after sys");
              }

              but it is executing. please help me.

              Comment


              • #8
                the proposed solution in the thread doesnt work for me. i dont export any war-archives or similar, i'm using the glassfish plugin which does the deploying.Attachment
                Attached Files

                Comment

                Working...
                X