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

问题描述 投票:0回答:3

当我练习Spring Tutorial 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 is
java.lang.IllegalArgumentException: error at ::0 can't find referenced
pointcut 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> 
java xml spring-aop pointcuts
3个回答
1
投票

我想你可能正在使用1.5版本的aspectjrt和aspectjweaver jars.use任何1.6版本你会得到它wworkin


0
投票

更换....

<aop:aspectj-autoproxy/>

与......

<aop:aspectj-autoproxy>
     <aop:include name="loggingAspectPointcuts"/>
</aop:aspectj-autoproxy>

0
投票

尝试使用正确版本的cglib.jar使用正确的版本2.1_3或最新版本

asm-3.3.1
cglib-2.2.2
aspectjrt-1.6.11
aspectweaver-1.6.11.

确保使用上述罐子。

© www.soinside.com 2019 - 2024. All rights reserved.