Missing Spring AOP libraries in STS
Asked Answered
C

2

4

I'm getting my feet wet with Spring. I downloaded STS and I'm following basic examples from Spring in Action Second Edition. I'm stuck when trying to implement basic AOP and I guess I'm just missing some specific libraries in my project.

I say so because annotations like @Aspect are not recognized in my classes like also <aop:config> in my xml.

This are my Maven Dependencies:

  • junit-4.7.jar
  • spring-test-3.0.2.RELEASE.jar
  • spring-context-3.0.2.RELEASE.jar
  • spring-aop-3.0.2.RELEASE.jar
  • aopalliance-1.0.jar
  • spring-beans-3.0.2.RELEASE.jar
  • spring-core-3.0.2.RELEASE.jar
  • commons-logging-1.1.1.jar
  • spring-expression-3.0.2.RELEASE.jar
  • spring-asm-3.0.2.RELEASE.jar
  • log4j-1.2.14.jar

Please let me know what libraries I'm missing and where to find them.

Thank you!

EDIT:

The following:

<bean id="performancePointcut"
        class="org.springframework.aop.aspectj.AspectJExpressionPointcut" >
    <property name="expression" value="execution(* Performer+.perform(..))" />
</bean>

throws the following exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performancePointcut' defined in file [C:\Users\Prova\Documents\STS\SpringIdol3\src\main\resources\META-INF\spring\spring-idol.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

DONE!

This aspectj-annotation-tutorial did the job with steps 1, 2, and 3.

It's been a fun Friday night....

Crooks answered 25/6, 2011 at 1:58 Comment(0)
K
14

Put these two dependencies in your pom.xml:

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.6.11</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.6.11</version>
    </dependency>
Karp answered 25/6, 2011 at 16:35 Comment(2)
Hi abalogh. I got it to work adding the libraries in STS through the project properties / java built path / libraries / add external jars. Is it the same thing or is there a particular reason why I should add those dependencies in the pom.xml instead? Thanks!Crooks
You wrote about 'Maven dependencies' - I assumed you are using Maven. If so, you shouldn't add manually jars to classpath, for one reason when you build with Maven, those won't be included in your binary.Karp
S
2

you may add maven dependencies:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.2.4.RELEASE</version>
</dependency>
Sites answered 31/12, 2015 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.