当我练习 Spring Tutorial 28 - Pointcuts and Wildcard Expressions时,我遇到了以下问题:
线程“main”org.springframework.beans.factory.BeanCreationException 中的异常: 在类路径资源中创建名称为“三角形”的 bean 时出错 [springPointcuts.xml]:bean初始化失败;嵌套异常是 java.lang.IllegalArgumentException: ::0 处的错误找不到引用 切入点 allGetters
您将在下面看到我的代码,非常感谢您为我的问题提供的解决方案。
LoggingAspectPointcuts :
package org.koushik.javabrains.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LoggingAspectPointcuts {
@Before("allGetters()")
public void LoggingAdvice(){
System.out.println("Advice run.Get Method called");
}
@Before("allGetters()")
public void secondAdvice() {
System.out.println("Second Advice executed ");
}
@Pointcut("execution(* get*())")
public void allGetters(){}
}
AopMainWildCardPointcuts :
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.koushik.javabrains.service.ShapeService;
public class AopMainWildCardPointcuts {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("springPointcuts.xml");
ShapeService shapeService= (ShapeService) ctx.getBean("shapeService");
System.out.println(shapeService.getCircle().getName());
}
springPointcuts.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<aop:aspectj-autoproxy/>
<bean name="triangle" class="org.koushik.javabrains.model.Triangle">
<property name="name" value="Triangle Name"/>
</bean>
<bean name="circle" class="org.koushik.javabrains.model.Circle">
<property name="name" value="Circle Name"/>
</bean>
<bean name="loggingAspectPointcuts" class="org.koushik.javabrains.aspect.LoggingAspectPointcuts"/>
</beans>