diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java index 47b39f72885d..5a384e85515d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor; import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; +import org.springframework.util.ClassUtils; /** * An AOT {@link BeanRegistrationAotProcessor} that detects the presence of @@ -30,13 +31,18 @@ * @author Sebastien Deleuze * @since 6.1 */ -public class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { +class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { + + private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut", + AspectJAdvisorBeanRegistrationAotProcessor.class.getClassLoader()); @Override public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { - Class beanClass = registeredBean.getBeanClass(); - if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) { - return new AspectJAdvisorContribution(beanClass); + if (aspectJPresent) { + Class beanClass = registeredBean.getBeanClass(); + if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) { + return new AspectJAdvisorContribution(beanClass); + } } return null; } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJAdvisorBeanRegistrationAotProcessorTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java similarity index 93% rename from spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJAdvisorBeanRegistrationAotProcessorTests.java rename to spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java index 80753338fa55..fedf491617b5 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJAdvisorBeanRegistrationAotProcessorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java @@ -14,11 +14,10 @@ * limitations under the License. */ -package org.springframework.aop.aspectj; +package org.springframework.aop.aspectj.annotation; import org.junit.jupiter.api.Test; -import org.springframework.aop.aspectj.annotation.AspectJAdvisorBeanRegistrationAotProcessor; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; @@ -38,7 +37,7 @@ * * @author Sebastien Deleuze */ -public class AspectJAdvisorBeanRegistrationAotProcessorTests { +class AspectJAdvisorBeanRegistrationAotProcessorTests { private final GenerationContext generationContext = new TestGenerationContext();