Announcement Announcement Module
Collapse
No announcement yet.
UnsatisfiedDependencyException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • UnsatisfiedDependencyException

    I have the following definition in the springconfig.xml file I get the UnsatisfiedDependencyException while I try to run the application Can anyone help me with what could be wrong



    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans >

    <!--CONFIG-->
    <bean id="businesslogicbean" class="org.springframework.aop.framework.ProxyFact oryBean">
    <!--<property name="proxyTargetClass">
    <value>true</value>
    </property>
    -->
    <property name="proxyInterfaces">
    <value>IBusinessLogic</value>
    </property>

    <property name="target">
    <ref local="beanTarget"/>
    </property>
    <property name="interceptorNames">
    <list>
    <value>theAroundAdvisor</value>
    </list>
    </property>
    </bean>

    <!--CLASS-->
    <bean id="beanTarget" class="BusinessLogic"/>

    <!--ADVISOR-->
    <!--Note: An advisor assembles pointcuts and advice-->

    <bean id="theAroundAdvisor" class="org.springframework.aop.support.ControlFlow Pointcut">
    <constructor-arg index="0" type="org.springframework.aop.support.ControlFlowP ointcut">
    <ref local="theAroundAdvice"/>
    </constructor-arg>
    </bean>

    <!--ADVICE-->
    <bean id="theAroundAdvice" class="AroundAdvice"/>
    </beans>

  • #2
    Can you post the stack trace of the error?

    Comment


    • #3
      Stack trace

      org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'theAroundAdvisor' defined in file [E:\Julius\springaoppart2source\springaoppart2sourc e\Around Advice Example\src\springconfig.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.Class]: Did you specify the correct bean references as generic constructor arguments?
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createArgumentArray(Abs tractAutowireCapableBeanFactory.java:622)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:495)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:306)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:260)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:221)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
      at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:282)
      at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
      at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:82)
      at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:67)
      at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:58)
      at MainApplication.main(MainApplication.java:10)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at com.intellij.rt.execution.application.AppMain.main (Unknown Source)
      Exception in thread "main" Process terminated with exit code 1

      Comment


      • #4
        There is no constructor of ControlFlowPointcut that takes an instance of ControlFlowPointcut. In the bean definition for theAroundAdvisor you are trying to instantiate the ControlFlowPointcut using an invalid constructor.

        Rob

        Comment


        • #5
          ControlFlowPointcut expects a constructor of type Class - java.lang.Class:

          [E:\Julius\springaoppart2source\springaoppart2sourc e\Around Advice Example\src\springconfig.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.Class]: Did you specify the correct bean references as generic constructor arguments?
          In your configuration you passing an object - the instance of theAroundAdivce. Moreover the type argument of constructor should be java.lang.Class and not org.springframework.aop.support.ControlFlowPointcu t.

          You should pass the class of theAroundAdvice like this:

          Code:
           <bean id="theAroundAdvisor" class="org.springframework.aop.support.ControlFlowPointcut">
          <constructor-arg index="0">
          <value>AroundAdvice</value>
          </constructor-arg>
          </bean>

          Comment


          • #6
            If I remove the type attribute of the constructor-arg then..

            i get the following exception

            org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'theAroundAdvisor' defined in file [E:\Julius\springaoppart2source\springaoppart2sourc e\Around Advice Example\src\springconfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [AroundAdvice] to required type [java.lang.Class]
            org.springframework.beans.TypeMismatchException: Failed to convert property value of type [AroundAdvice] to required type [java.lang.Class]
            at org.springframework.beans.BeanWrapperImpl.doTypeCo nversionIfNecessary(BeanWrapperImpl.java:1015)
            at org.springframework.beans.BeanWrapperImpl.doTypeCo nversionIfNecessary(BeanWrapperImpl.java:892)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createArgumentArray(Abs tractAutowireCapableBeanFactory.java:597)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:495)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:306)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:260)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:221)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
            at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:282)
            at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
            at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:82)
            at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:67)
            at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:58)
            at MainApplication.main(MainApplication.java:10)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at com.intellij.rt.execution.application.AppMain.main (Unknown Source)

            Comment


            • #7
              Using..

              <bean id="theAroundAdvisor" class="org.springframework.aop.support.ControlFlow Pointcut">
              <constructor-arg index="0">
              <value>AroundAdvice</value>
              </constructor-arg>
              </bean>

              I get the following error !!
              org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'businesslogicbean' defined in file [E:\Julius\springaoppart2source\springaoppart2sourc e\Around Advice Example\src\springconfig.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigExcepti on: Unknown advisor type class org.springframework.aop.support.ControlFlowPointcu t; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry,which may also be target or TargetSource; nested exception is org.springframework.aop.framework.adapter.UnknownA dviceTypeException: No adapter for Advice of class [org.springframework.aop.support.ControlFlowPointcu t]
              org.springframework.aop.framework.AopConfigExcepti on: Unknown advisor type class org.springframework.aop.support.ControlFlowPointcu t; Can only include Advisor or Advice type beans in interceptorNames chain except for last entry,which may also be target or TargetSource; nested exception is org.springframework.aop.framework.adapter.UnknownA dviceTypeException: No adapter for Advice of class [org.springframework.aop.support.ControlFlowPointcu t]
              org.springframework.aop.framework.adapter.UnknownA dviceTypeException: No adapter for Advice of class [org.springframework.aop.support.ControlFlowPointcu t]
              at org.springframework.aop.framework.adapter.DefaultA dvisorAdapterRegistry.wrap(DefaultAdvisorAdapterRe gistry.java:49)
              at org.springframework.aop.framework.ProxyFactoryBean .namedBeanToAdvisor(ProxyFactoryBean.java:465)
              at org.springframework.aop.framework.ProxyFactoryBean .addAdvisorOnChainCreation(ProxyFactoryBean.java:4 28)
              at org.springframework.aop.framework.ProxyFactoryBean .createAdvisorChain(ProxyFactoryBean.java:331)
              at org.springframework.aop.framework.ProxyFactoryBean .setBeanFactory(ProxyFactoryBean.java:197)
              at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:338)
              at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:260)
              at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:221)
              at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
              at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:276)
              at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
              at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:82)
              at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:67)
              at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:58)
              at MainApplication.main(MainApplication.java:10)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:324)
              at com.intellij.rt.execution.application.AppMain.main (Unknown Source)
              Exception in thread "main" Process terminated with exit code 1

              Comment


              • #8
                What error do you actually get?

                I get the following error !!
                org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'businesslogicbean' defined in file
                You are mixing definitions here - for proxy factory bean as interceptors you need an advisor or advice as the error also says. You are trying to pass in a pointcut.

                Read the AOP documentation and the javadocs of ProxyFactoryBean.

                Comment


                • #9
                  In the constructor arg for ControlFlowPoincut you must pass the fully qualified name of the class you want to pointcut. Check the JavaDoc for more details.

                  Note that ControlFlowPointcut is not an Advisor implementation. You need to configure an Advisor implementation such as DefaultPointcutAdvisor with this pointcut and your advice.

                  Rob

                  Comment


                  • #10
                    Thanks a lot

                    That was really helpful !!

                    Comment

                    Working...
                    X