简体   繁体   English

Spring没有找到AspectJ包

[英]Spring not finding AspectJ package

I'm beggining my journey with Spring, trying to use AspectJ in Spring 3.2.我开始使用 Spring 开始我的旅程,尝试在Spring 3.2 中使用AspectJ Im following book Spring in Action .我正在关注《 Spring in Action》一书。 Author uses AspectJ by importing aspectJ packages this way:作者通过以下方式导入 aspectJ 包来使用 AspectJ:

import org.aspectj.lang.annotation.Aspect

However using that leaves me with然而,使用它让我

package org.aspectj.lang.annotation does not exist

I tried importing aspectj.jar (version 1.8.4) to my libraries in NetBeans , without any effect.我尝试将aspectj.jar (1.8.4 版)导入我在NetBeans中的库,但没有任何效果。 I have the jar just bellow dozen of SPRING FRAMEWORK 3.2.3 RELEASE xxxxxx's .我的罐子刚好低于十几个SPRING FRAMEWORK 3.2.3 RELEASE xxxxxx's It still does not find the package.它仍然找不到包。 What could cause this issue?什么可能导致这个问题? Here's the beggining of my beans.xml这是我的 beans.xml 的开始

    <?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
" xmlns:util="http://www.springframework.org/schema/util">

    <context:component-scan base-package="heyspring">

    </context:component-scan>

    <aop:aspectj-autoproxy>

I suggest you move to Maven我建议你搬到 Maven

Even if you want to work without Maven, read the following note carefully.即使您想在没有 Maven 的情况下工作,请仔细阅读以下说明。

Note : even in Maven Central Repository you are able to download the jars required according with my dependencies shared below注意:即使在Maven 中央存储库中,您也可以根据我在下面共享的依赖项下载所需的jars

Be totally sure you have the following in your pom.xml or equivalent jars files:完全确保您的pom.xml等效jars文件中有以下内容:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${springframework.version}</version>
</dependency>

The following is mandatory以下为必填项

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>${aspectj.version}</version>
</dependency>
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>${aspectj.version}</version>
</dependency>

Of course you must set or configure each version, for Spring and AOP.当然,您必须为 Spring 和 AOP 设置或配置每个版本。

I have these three dependencies and work fine in my projects.我有这三个依赖项并且在我的项目中工作正常。

For me reason was using using <scope> when copying from Maven Repository ( https://mvnrepository.com/artifact/org.aspectj/aspectjrt/1.9.9.1 ).对我来说,从 Maven 存储库( https://mvnrepository.com/artifact/org.aspectj/aspectjrt/1.9.9.1 )复制时使用<scope>的原因。


    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.9.9.1</version>
<!--      <scope>runtime</scope>-->
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.9.9.1</version>
<!--      <scope>runtime</scope>-->
    </dependency>

I commented <scope>...</scope> tag , which was probably only for runtime thats why ide cant find its repos .我评论<scope>...</scope>标记,这可能仅适用于runtime ,这就是 ide 找不到它的 repos 的原因。 After removing this It starts working or we can add compile .删除后它开始工作,或者我们可以添加compile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM