Announcement Announcement Module
Collapse
No announcement yet.
Could not instantiate bean class[org.springframework.aop.aspectj.AspectJPointcutAdv i Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not instantiate bean class[org.springframework.aop.aspectj.AspectJPointcutAdv i

    Hi I am Manjunath I am facing a issue while passing a userdefined argument through spring aop.

    this is my context xml.

    HTML 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"
           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">
    
    	<bean id="EncryptionHandler" class="example.EncryptionHandler"/>
    	<bean id="AuditHandler" class="example.AuditHandler"/>
    	<bean id="userDetails" class="example.UserDetails">
    	<property name="userName">
    		<value>monem</value>
    	</property>
    	<property name="id">
    		<value>210080</value>
    	</property>
    	</bean>
    
    	<bean id="Demographics" class="example.CaptureDemogrphicsImpl"/>
    	
    	<aop:config>
    		<aop:aspect id="EncryptionAspect" ref="EncryptionHandler">
    			<aop:around
    			      method="encryption" 
    			      pointcut="execution(* example.CaptureDemogrphics.submitDemoInfo(Userdetails)) and args(userdetails)"/>
    		</aop:aspect>
    		
    		<!--<aop:aspect id="AuditAspect" ref="AuditHandler">
    			
    			<aop:after-returning
    			      method="audit"		
    			      returning ="info"
    			      pointcut="execution(* example.CaptureDemogrphics.submitDemoInfo(String,String))"/>
    		</aop:aspect>
    	--></aop:config>
    
    </beans>
    my advice class is

    Code:
    package example;
    
    import example.UserDetails;
    
    
    
    public class EncryptionHandler {
    	
    
    
    	EncryptionHandler(){
    		
    		System.out.println("I am in the EncryptionHandler constructor");
    	}
    
    	public String encryption(UserDetails userdetails) {
    		   String username =  userdetails.getUserName();
    		   String id = (String) userdetails.getId();
    		   System.out.println("Demographics Data   userName= "+ username +"		"+ "pass= " + id);
    		return "data is encrypted hash map";
    	   }
    
    
    }
    target interface

    Code:
    package example;
    
    import example.UserDetails;
    
    public interface CaptureDemogrphics {
    	
    	public String submitDemoInfo(UserDetails userdetails);
    }
    target implementation class


    Code:
    package example;
    
    public class CaptureDemogrphicsImpl implements CaptureDemogrphics {
    
    	public String submitDemoInfo(UserDetails userdetails) {
    	
    		return "return userdetails bean";
    	}
    	
    	
    }
    this is my calling class


    Code:
    package example;
    
    import example.UserDetails;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class CaptureDemoUI {
    
    	public static void main(String[] args) {
    		ApplicationContext context = new ClassPathXmlApplicationContext(
    				"example/aopContext.xml");
    		CaptureDemogrphics CaptureDemogrphicsService = (CaptureDemogrphics) context
    				.getBean("Demographics");
    		UserDetails userDetails = (UserDetails) context
    		.getBean("userDetails");
    		userDetails.setUserName("monem");
    		userDetails.setId("210080");
    
    		String returnval = CaptureDemogrphicsService
    				.submitDemoInfo(userDetails);
    
    		
    		System.out.println("returnvalue :- " + returnval);
    
    	}
    
    }

    I am getting this error while calling submitDemoInfo(userDetails) with around advice

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'EncryptionHandler' defined in class path resource [example/aopContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:379)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:353)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 45)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:242)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:400)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:736)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:369)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:123)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:66)
    at example.CaptureDemoUI.main(CaptureDemoUI.java:12)
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]
    at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:239)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:855)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:765)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:412)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:383)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:353)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 45)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:242)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.aop.framework.autoproxy.BeanFa ctoryAdvisorRetrievalHelper.findAdvisorBeans(BeanF actoryAdvisorRetrievalHelper.java:87)
    at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.findCandidateAdvisors(Ab stractAdvisorAutoProxyCreator.java:98)
    at org.springframework.aop.aspectj.autoproxy.AspectJA wareAdvisorAutoProxyCreator.shouldSkip(AspectJAwar eAdvisorAutoProxyCreator.java:105)
    at org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.postProcessBeforeInstantiation( AbstractAutoProxyCreator.java:244)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors BeforeInstantiation(AbstractAutowireCapableBeanFac tory.java:724)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveBeforeInstantiat ion(AbstractAutowireCapableBeanFactory.java:695)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:373)
    please give solution for this (it is urgent for my project)

    thanks,
    Manjunath

  • #2
    Your encryption class is wrong, if you read the documentation for the around advice.

    The first parameter of the advice method must be of type ProceedingJoinPoint. Within the body of the advice, calling proceed() on the ProceedingJoinPoint causes the underlying method to execute. The proceed method may also be called passing in an Object[] - the values in the array will be used as the arguments to the method execution when it proceeds.
    So change your method signature.

    Comment


    • #3
      hi,

      do u mean, i need to change my aopcontext.xml file.
      If we pass String param in the execution of aopcontext.xml file , it works fine but when we pass an object instance it gives error

      Comment


      • #4
        Read the documentation regarding around advices!

        Code:
        public class EncryptionHandler {
        
          EncryptionHandler(){		
            System.out.println("I am in the EncryptionHandler constructor");
          }
        
          public String encryption(ProceedingJoinPoint pjp, UserDetails userdetails) {
            String username =  userdetails.getUserName();
            String id = (String) userdetails.getId();
            System.out.println("Demographics Data   userName= "+ username +"		"+ "pass= " + id);
            return "data is encrypted hash map";
          }
        }

        Comment


        • #5
          Marten,

          I modified my EncrytionHandler to wht ever u suggested still it is giving the same error

          Feb 14, 2008 7:46:37 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
          INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@1af9e22: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@1af9e22]; startup date [Thu Feb 14 19:46:37 GMT+05:30 2008]; root of context hierarchy
          Feb 14, 2008 7:46:38 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
          INFO: Loading XML bean definitions from class path resource [example/aopContext.xml]
          Feb 14, 2008 7:46:38 PM org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
          INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@1af9e22]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@199f91c
          Feb 14, 2008 7:46:38 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
          INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@199f91c: defining beans [EncryptionHandler,AuditHandler,userDetails,Demogra phics,org.springframework.aop.config.internalAutoP roxyCreator,org.springframework.aop.aspectj.Aspect JPointcutAdvisor#0]; root of factory hierarchy
          Feb 14, 2008 7:46:38 PM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
          INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@199f91c: defining beans [EncryptionHandler,AuditHandler,userDetails,Demogra phics,org.springframework.aop.config.internalAutoP roxyCreator,org.springframework.aop.aspectj.Aspect JPointcutAdvisor#0]; root of factory hierarchy
          Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'EncryptionHandler' defined in class path resource [example/aopContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:379)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:353)
          at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 45)
          at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:242)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:400)
          at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:736)
          at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:369)
          at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:123)
          at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:66)
          at example.CaptureDemoUI.main(CaptureDemoUI.java:11)
          Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]
          at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:239)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:855)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:765)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:412)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:383)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:353)
          at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 45)
          at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:242)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
          at org.springframework.aop.framework.autoproxy.BeanFa ctoryAdvisorRetrievalHelper.findAdvisorBeans(BeanF actoryAdvisorRetrievalHelper.java:87)
          at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.findCandidateAdvisors(Ab stractAdvisorAutoProxyCreator.java:98)
          at org.springframework.aop.aspectj.autoproxy.AspectJA wareAdvisorAutoProxyCreator.shouldSkip(AspectJAwar eAdvisorAutoProxyCreator.java:105)
          at org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.postProcessBeforeInstantiation( AbstractAutoProxyCreator.java:244)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors BeforeInstantiation(AbstractAutowireCapableBeanFac tory.java:724)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveBeforeInstantiat ion(AbstractAutowireCapableBeanFactory.java:695)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:373)
          ... 12 more
          Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdv isor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]
          at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:98)
          at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:87)
          at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:233)
          ... 29 more
          Caused by: java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]
          at org.aspectj.weaver.tools.PointcutParser.parsePoint cutExpression(PointcutParser.java:315)
          at org.springframework.aop.aspectj.AspectJExpressionP ointcut.buildPointcutExpression(AspectJExpressionP ointcut.java:197)
          at org.springframework.aop.aspectj.AspectJExpressionP ointcut.checkReadyToMatch(AspectJExpressionPointcu t.java:184)
          at org.springframework.aop.aspectj.AspectJExpressionP ointcut.getMethodMatcher(AspectJExpressionPointcut .java:170)
          at org.springframework.aop.aspectj.AbstractAspectJAdv ice.buildSafePointcut(AbstractAspectJAdvice.java:1 89)
          at org.springframework.aop.aspectj.AspectJPointcutAdv isor.<init>(AspectJPointcutAdvisor.java:51)
          at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
          at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
          at java.lang.reflect.Constructor.newInstance(Unknown Source)
          at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:83)
          ... 31 more

          Comment


          • #6
            Next to that specify the fully qualified classname for UserDetails in your pointcut...

            Code:
            <aop:config>
            		<aop:aspect id="EncryptionAspect" ref="EncryptionHandler">
            			<aop:around
                      method="encryption" 
            			    pointcut="execution(* example.CaptureDemogrphics.submitDemoInfo(example.Userdetails)) and args(userdetails)"/>
            		</aop:aspect>		
            </aop:config>
            Which is given away by your exception.

            Code:
            Caused by: java.lang.IllegalArgumentException: warning no match for this type name: Userdetails [Xlint:invalidAbsoluteTypeName]

            Comment


            • #7
              Now it working properly

              Thank u Marten,

              Comment

              Working...
              X