Announcement Announcement Module
Collapse
No announcement yet.
Simple Test of reusing the aspects.(error at ::0 formal unbound in pointcut) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Test of reusing the aspects.(error at ::0 formal unbound in pointcut)

    Hi All,

    I am trying simple tests to reuse an existing Pointcut to create new Pointcut and getting the Error "error at ::0 formal unbound in pointcut" .

    Here is my code..

    GlobalAspects.java

    Code:
    package com.cert.spring.aop;
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    @Aspect
    public class GlobalAspects {
    
    	private static Logger logger = LoggerFactory.getLogger(GlobalAspects.class);
    
    	@Pointcut("execution(* com.cert.spring.core.*.*(..))")
    	public void beforeMethodCall() {
    		//logger.info("Before calling the Method Name ="+jp.getSignature().getName());
    		//logger.info("Target    ="+jp.getTarget());
    		logger.info("Here in beforeMethodCall() ");
    	}
    }
    ExtendedAspect.java

    Here i want to only log methods which match the point cut defined in GlobalAspect and which have only one argument of type int

    Code:
    package com.cert.spring.aop;
    
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;
    import org.slf4j.LoggerFactory;
    
    @Aspect
    public class ExtendedAspect1 {
    
    	private static org.slf4j.Logger logger = LoggerFactory.getLogger(ExtendedAspect1.class);
    	
    	@Before("com.cert.spring.aop.GlobalAspects.beforeMethodCall() && args(int))")
    	public void beforeMethodCallArg(int counter) {
    		//logger.info("Before calling the Method Name ="+jp.getSignature().getName());
    		logger.info("Counter     ="+counter);
    		logger.info("Here in beforeMethodCallArg() ");
    	}
    	
    }
    My Simple Test POJO Object (DataObject )

    Code:
       package com.cert.spring.core;
    
    public class DataObject {
    
    	int counter =0;
    	String title = null;
    	public int getCounter() {
    		return counter;
    	}
    	public void setCounter(int counter) {
    		this.counter = counter;
    	}
    	public String getTitle() {
    		return title;
    	}
    	public void setTitle(String title) {
    		this.title = title;
    	}
    }
    My Test Class..

    Code:
    public class TestMain {
    
    	/**
    	 * @param args
    	 */
    	
    	private static final Logger logger = LoggerFactory.getLogger(TestMain.class);
    	
    	private ApplicationContext appContext = null;
    	
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		TestMain testMaion = new TestMain();
    		testMaion.init();
    	}
    	public void init(){
    		appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
    		DataObject dataObject = (DataObject)appContext.getBean("myTestBean");
    		logger.info(" Counter = "+dataObject.getCounter());
    		logger.info(" Title   = "+dataObject.getTitle());
    		dataObject.setCounter(10);
    	}
    
    }
    Finally my Config File..

    Code:
    <?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" 
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    	http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    
    	<bean id="myTestBean" class="com.cert.spring.core.DataObject">
    	</bean>
    	
    	<bean id="globalAspects" class="com.cert.spring.aop.GlobalAspects"/>
    	
    	<bean id="testAspect" class="com.cert.spring.aop.ExtendedAspect1" /> 
    	<aop:aspectj-autoproxy/>
    </beans>
    Error i am getting is:

    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTestBean' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:430)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at TestMain.init(TestMain.java:25)
    	at TestMain.main(TestMain.java:22)
    Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
    	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:197)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:184)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:165)
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:198)
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:253)
    	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:287)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:113)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:85)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:296)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:357)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
    	... 15 more
    Initially i tried the @Before annotation instead of the @Pointcut and was getting the Error:

    Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut beforeMethodCall

    As it is treating the beforeMethodCall() as a pointcut and hence i changed the Annotation to @Pointcut

    Thanks
    Sateesh

  • #2
    I see a couple of problems:

    1. Did you mean @Before instead of @Pointcut in GlobalAspects?

    2. Change
    Code:
    @Before("com.cert.spring.aop.GlobalAspects.beforeMethodCall() && args(int))")
    to
    Code:
    @Before("com.cert.spring.aop.GlobalAspects.beforeMethodCall() && args(counter))")
    -Ramnivas

    Comment

    Working...
    X