Missing Spring AOP libraries in STS

蹲街弑〆低调 提交于 2020-01-01 12:34:09

问题


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


回答1:


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>



回答2:


you may add maven dependencies:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.2.4.RELEASE</version>
</dependency>


来源:https://stackoverflow.com/questions/6475313/missing-spring-aop-libraries-in-sts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!