gpt4 book ai didi

java - 当我尝试使用切入点和通配符表达式创建 Bean 时,为什么会出现错误?

转载 作者:行者123 更新时间:2023-12-01 15:01:42 25 4
gpt4 key购买 nike

当我练习的时候Spring教程28 - 切入点和通配符表达式,我遇到以下问题:

Exception in thread"main"org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'triangle' defined in class path resource[springPointcuts.xml]: Initialization of bean failed; nested exception isjava.lang.IllegalArgumentException: error at ::0 can't find referencedpointcut allGetters

You will see my codes belowI would much appreciate your solution for my problem.

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>

最佳答案

我猜你可能正在使用1.5版本的aspectjrt和aspectjweaver jars。使用任何1.6版本你都会得到它工作

关于java - 当我尝试使用切入点和通配符表达式创建 Bean 时,为什么会出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13548173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com