Missing Spring AOP libraries in STS

2019-04-10 23:55发布

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....

2条回答
倾城 Initia
2楼-- · 2019-04-11 00:17

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>
查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-11 00:18

you may add maven dependencies:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.2.4.RELEASE</version>
</dependency>
查看更多
登录 后发表回答