Announcement Announcement Module
Collapse
No announcement yet.
Spring AOP set up Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring AOP set up

    Part 1:
    org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from class path resource [ApplicationContextAOP.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

    Response to Part 1:
    com.springsource.org.aopalliance-1.0.0 library

    Part 2:
    [org.springframework.aop.aspectj.AspectJMethodBefor eAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.aspectj.AspectJExpressionP ointcut] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

    Response to Part 2:
    aspectweaver.jar

    Were those correct libraries?

    Part 3:

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 49
    execution(*com.idol.performers.Performer.perform(. .))


    What is response to part 3?

    The example is taken directly from Spring In Action 3rd , which was released few months ago... and book says that
    Code:
     (..)
    means taking any arguments...

    I no longer understand whether I use AspectJ or Spring AOP... My head is collapsing.


    MY XML:

    Code:
    <?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    
    
    
    
    <aop:config>
    	<aop:aspect ref="audience">
    		
    		<!-- Before performance -->		
    		
    		<aop:before pointcut="execution(*com.idol.performers.Performer.perform(..))" method="takeSeats"/>
    		
    		<aop:before pointcut="execution(*com.idol.performers.Performer.perform(..))" method="turnOffCellPhones" />
    		
    		<!-- After performance -->	
    		
    		<aop:after-returning pointcut="execution(*com.idol.performers.Performer.perform(..))" method="applaud" />
    		
    		<!-- After bad performance(exception thrown) -->	
    		
    		<aop:after-throwing pointcut="execution(*com.idol.performers.Performer.perform(..))" method="demandRefund" />
    
    	</aop:aspect>
    </aop:config>
    
    
    <bean id="audience" class="com.idol.Audience" />
    <bean id="poeticDuke" class="com.performers.Juggler" />
    
    
    </beans>
    There is no quick guide on a single page to indicate at least which libraries it requires.
    So I presume good part of us found that out of numerous exceptions, why it was difficult to add those to Spring library will be eternal mystery for me.(I guess there is some satanic part in developers to make people cry, I am in instance on the verge of vomiting, it happens when errors ironically never end)
    Last edited by Aubergine; Aug 19th, 2011, 07:22 PM.

  • #2
    Finally set it up and running. Latest problem is because of draconian error detection, apparently there has to be space between '*' and com. . I really hope somebody will find this thread and save time which I couldn't(3 hours just to write first and very basic example) because somewhere someone misses one library, but not the other and in other place other way around. Both libraries are suitable and required for Spring 3 AOP.

    Good Luck,

    Comment


    • #3
      Both libraries are suitable and required for Spring 3 AOP.
      No they aren't it depends which form of aspect declaration you use. You choose (or at least in the book) to use the AspectJ expression language which adds the extra dependency on AspectJ. If you wouldn't use that form of expression you wouldn't need the AspectJ jar...

      Also the source code can be downloaded from the manning website, those projects use maven to manage the dependencies (I always suggest a dependency management piece like maven/ant+ivy/gradle because it saves you a lot of headaches).

      Comment


      • #4
        Originally posted by Marten Deinum View Post
        No they aren't it depends which form of aspect declaration you use. You choose (or at least in the book) to use the AspectJ expression language which adds the extra dependency on AspectJ. If you wouldn't use that form of expression you wouldn't need the AspectJ jar...

        Also the source code can be downloaded from the manning website, those projects use maven to manage the dependencies (I always suggest a dependency management piece like maven/ant+ivy/gradle because it saves you a lot of headaches).
        These three words are hated by me, I thought that Eclipse use maven to manage all the dependencies, but now seems that it doesn't since I had to add libraries explicitly into the project and classpath, I still don't understand how they work and when I tried to learn them I got mega manuscript for 30 pages (ant or maven I don't remember), I am human being I can't learn everything... Maybe my opinion will change when I finish university, but I will strive to avoid these.

        Comment


        • #5
          I thought that Eclipse use maven to manage all the dependencies,
          Only if you create a maven project (instead of a java project)... I really suggest a book on dependency management or reading more about maven or one of the other choices. It saves you really a lot of pain in searching for dependencies and avoiding duplicate jars etc...

          Comment


          • #6
            maven

            Originally posted by Marten Deinum View Post
            Only if you create a maven project (instead of a java project)... I really suggest a book on dependency management or reading more about maven or one of the other choices. It saves you really a lot of pain in searching for dependencies and avoiding duplicate jars etc...
            Found on stackoverflow
            http://www.sonatype.com/books/mvnex-...blic-book.html - seems to be the right one.

            I know it is a little off the topic, but maybe you know - I will be taking Spring Core training course soon, what do they encourage to use in there? Maven or Ant and which IDE?

            Comment


            • #7
              If you do the core spring training you will receive a usb stick with software and instructions, you don't need to pre-install anything (if you do it would complicate things). The environment is based on STS and Maven...

              Comment

              Working...
              X