Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring not finding AspectJ package

I'm beggining my journey with Spring, trying to use AspectJ in Spring 3.2. Im following book Spring in Action. Author uses AspectJ by importing aspectJ packages this way:

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. I have the jar just bellow dozen of 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

    <?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>
like image 550
blahblah Avatar asked Mar 18 '26 15:03

blahblah


2 Answers

I suggest you move to Maven

Even if you want to work without Maven, read the following note carefully.

Note: even in Maven Central Repository you are able to download the jars required according with my dependencies shared below

Be totally sure you have the following in your pom.xml or equivalent jars files:

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

I have these three dependencies and work fine in my projects.

like image 124
Manuel Jordan Avatar answered Mar 21 '26 03:03

Manuel Jordan


For me reason was using using <scope> when copying from Maven Repository (https://mvnrepository.com/artifact/org.aspectj/aspectjrt/1.9.9.1).


    <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 . After removing this It starts working or we can add compile.

like image 20
Because i hate myself Avatar answered Mar 21 '26 05:03

Because i hate myself