0

When I practice Spring Tutorial 28 - Pointcuts and Wildcard Expressions, I encounter the following problem :

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

You will see my codes below I 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> 
John Saunders
  • 160,644
  • 26
  • 247
  • 397

3 Answers3

1

I guess u might be using the 1.5 version of aspectjrt and aspectjweaver jars.use any of the 1.6 versions n u will get it wworkin

0

Replace....

<aop:aspectj-autoproxy/>

with ...

<aop:aspectj-autoproxy>
     <aop:include name="loggingAspectPointcuts"/>
</aop:aspectj-autoproxy>
Vikram
  • 4,162
  • 8
  • 43
  • 65
0

Try to use the correct version of cglib.jar use the cirrect version 2.1_3 or latest

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

Make sure you use the above-mentioned jars.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135