Announcement Announcement Module
Collapse
No announcement yet.
AspectJ + OC4J + Spring AOP gives problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ + OC4J + Spring AOP gives problems

    I'm using AspectJ and Spring AOP to advice the same beans (applicationservices) , and get an error when I try to add 2 different styles aspects (weaving aspects-AspectJ, proxy aspects-SpringAOP)

    Code:
      at oracle.oc4j.admin.internal.DeployerBase.execute(DeployerBase.java:126)
         [java]     at com.evermind.server.administration.DefaultApplicationServerAdministrator.internalDeploy(DefaultApplicationServerAdministrator.java:446)
         [java]     ... 8 more
         [java] Error: Deploy error: deploy failed!: ; nested exception is: 
         [java]     oracle.oc4j.admin.internal.DeployerException: Error creating bean with name 'authorisationAppService' defined in ServletContext resource [/WEB-INF/applicationcontext-authorization-appservice.xml]: Cannot resolve reference to bean 'userRepository' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in ServletContext resource [/WEB-INF/applicationcontext-database.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationcontext-database.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot create inner bean '(inner bean)' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'applicationServiceCallPointcut' while setting constructor argument with index 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationServiceCallPointcut': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJExpressionPointcut]: Constructor threw exception; nested exception is oracle.classloader.util.AnnotatedLinkageError: Class org/aspectj/weaver/reflect/AnnotationFinder violates loader constraints
    
         [java]       Invalid class: org.aspectj.weaver.reflect.AnnotationFinder
         [java]              Loader: oc4j:10.1.3
         [java]         Code-Source: /java/servers/oc4j/j2ee/home/applib/aspectjweaver.jar
         [java]       Configuration: system property java.class.path
    
         [java]     Dependent class: org.aspectj.weaver.reflect.ReflectionWorld
         [java]              Loader: oc4j:10.1.3
         [java]         Code-Source: /java/servers/oc4j/j2ee/home/applib/aspectjweaver.jar
         [java]       Configuration: system property java.class.path
    This is the bean configuration for the transaction aspect:
    Code:
     <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect"
              factory-method="aspectOf">
    
            <property name="transactionManager"
                      ref="transactionManager"/>
        </bean>

    OC4J is started with the AspectJ agent, and I'm using a aop.xml to prevent all classes from being inspected:

    Code:
    <aspectj>
        <weaver>
            <include within="foo.appservices..*"/>
        </weaver>
    </aspectj>
    If I use only the AspectJ part to set up my @transactional aspects, everything is ok. I have added the @transactional annotations to my applicationservice-implementations.

    This is one of my application services:
    Code:
    public class QueryIntakeAppServiceImpl implements QueryIntakeAppService {
    
        private final static Logger logger = Logger.getLogger(QueryIntakeAppServiceImpl.class);
    
        public QueryIntakeAppServiceImpl() {
        }
    
        @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
        public QueryProgress submit(String query, Credentials credentials) throws NotAuthorizedException {
            ... junk
        }
    }
    If I add profiling by Spring AOP, I get an error:

    This is the configuration for the profiling:
    Code:
    <aop:config>
            <aop:pointcut id="applicationServiceCallPointcut"
                          expression="execution(* foo.appservices.*.*AppService+.*(..))"/>
    
            <aop:aspect id="loggingAspect" ref="profiler">
                <aop:around
                        method="profile"
                        pointcut-ref="applicationServiceCallPointcut"/>
            </aop:aspect>
        </aop:config>
    
        <!-- the profiler that does the actual profiling -->
        <bean id="profiler"
              class="foo.aspects.JamonProfiler"/>
    This is the aspect:
    Code:
    public class JamonProfiler {
        
        public Object profile(ProceedingJoinPoint jp) throws Throwable {
            String name = jp.getSignature().getDeclaringTypeName() + "." + jp.getSignature().getName();
            Monitor mon = MonitorFactory.start(name);
            try {
                return jp.proceed();
            } finally {
                mon.stop();
            }
        }
    }
    Last edited by Alarmnummer; Dec 28th, 2006, 06:43 AM.

  • #2
    Looking at your stacktrace it looks like a classloading issue. Do you have 2 instances of the aspectj jars hanging around in the classpath somewhere?

    This error generally occurs when you are trying to reload a already loaded class. Now if the class would already be loaded by the servers general classloader this could interfere the web-application classloader.

    Comment


    • #3
      Can you tell me how to start the OC4J with the AspectJ agent?

      Comment


      • #4
        I encounter exactly the same problem as described in the first post.

        The steps I took to produce the error were:
        1. Add the aspectweaver.jar to the lib directory shared by all applications found at OC4J_HOME/j2ee/home/applib
        2. Made sure that the aspectweaver.jar is unique (does not appear twice on the classpath)
        3. Added a aop.xml to a META-INF directory on my application's (ear) classpath
        4. Added the agent argument to the startup script (oc4j.cmd): -javaagent:<path-to-ajlibs>/aspectjweaver.jar

        I dare to say that this is a bug.
        Last edited by Urs Peter; Jun 6th, 2007, 07:49 AM.

        Comment


        • #5
          Originally posted by javiere View Post
          Can you tell me how to start the OC4J with the AspectJ agent?
          Specify this as VM argument (Java 5+): -javaagent:<path-to-ajlibs>/aspectjweaver.jar

          See here for reference.

          regards,
          Andreas

          Comment


          • #6
            Can someone post articles, examples, or whatever on how to implement aspect weaving at compile-time (instead of doing it at run-time)?

            I've found that doing it at runtime is slow (at least in Tomcat).

            Thanks!

            Comment


            • #7
              Originally posted by javiere View Post
              Can someone post articles, examples, or whatever on how to implement aspect weaving at compile-time (instead of doing it at run-time)?
              You'll need the AspectJ compiler for that. Have a look at the AspectJ page.

              Regards,
              Andreas

              Comment


              • #8
                Originally posted by Urs Peter View Post
                I encounter exactly the same problem as described in the first post.

                The steps I took to produce the error were:
                1. Add the aspectweaver.jar to the lib directory shared by all applications found at OC4J_HOME/j2ee/home/applib
                2. Made sure that the aspectweaver.jar is unique (does not appear twice on the classpath)
                3. Added a aop.xml to a META-INF directory on my application's (ear) classpath
                4. Added the agent argument to the startup script (oc4j.cmd): -javaagent:<path-to-ajlibs>/aspectjweaver.jar

                I dare to say that this is a bug.
                Could we please have a reaction on the initial post, which is backed up by my own experiences. (LTW does not work on OC4j in combination with Spring's runtime weaving)

                Comment


                • #9
                  another OC4J + Spring load time weaving that doesn't work

                  Another vote here for solving this issue. We're encountering the same error when configuring LTW on OC4J 10.1.3

                  Comment


                  • #10
                    I am having the same problem with OC4J 10.1.3.2 when I mix aspectjweaver and spring interceptors...

                    Any luck anybody?

                    Right now I am trying to find the sources for aspectjweaver-1.5.3, but no luck... they seem to be only in the cvs, but I could not find them here (http://dev.eclipse.org/viewcvs/index...=Tools_Project)

                    Comment

                    Working...
                    X