Announcement Announcement Module
Collapse
No announcement yet.
AOP Errors. Cannot create inner bean. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP Errors. Cannot create inner bean.

    This is my Spring configuration 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"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    	
    	<bean id="tongue" class="it.robertocasadei.spring.ItalianGreet">
    		<constructor-arg value="#{1+3}" />
    		<property name="prefix">
    			<bean id="pref" class="it.robertocasadei.spring.Pre" />
    		</property>
    	</bean>
    	
    	<bean id="roby" class="it.robertocasadei.spring.Person" autowire="constructor">
    		<!-- <constructor-arg ref="tongue" /> -->
    	</bean>
    	
    	<bean id="apojo" class="it.robertocasadei.spring.AspectPOJO" />
    	
    	<aop:config>
    		<aop:aspect ref="apojo">
    			<aop:after-returning pointcut="execution(* it.robertocasadei.spring.Person.speak(..))" method="bye" />
    		</aop:aspect>
    	</aop:config>
    	
    </beans>
    If I drop down the <aop:after> line, the application executes successfully.

    Here's the error:
    Code:
    11-ott-2011 12.03.46 org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@758fc9: startup date [Tue Oct 11 12:03:45 CEST 2011]; root of context hierarchy
    11-ott-2011 12.03.46 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [greet.xml]
    11-ott-2011 12.03.46 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4fce71: defining beans [tongue,roby,apojo,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0]; root of factory hierarchy
    11-ott-2011 12.03.46 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4fce71: defining beans [tongue,roby,apojo,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0]; root of factory hierarchy
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tongue' defined in class path resource [greet.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.aspectj.AspectJAfterReturningAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.aspectj.AspectJExpressionPointcut] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at it.robertocasadei.spring.Execute.main(Execute.java:9)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.aspectj.AspectJAfterReturningAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.aspectj.AspectJExpressionPointcut] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException
    ................................................
    ................................................
    I just wanted to do some tests, but it doesn't work

  • #2
    Have you read the stack trace?

    Code:
    java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException
    You seem to be missing an aspects jar (probably the weaver one).

    Comment


    • #3
      Why are there a million of Spring dependencies that one developer has to look for? :\

      I've added references for the following JARs: aspectjweaver-1.6.11, cglib-2.2.2, com.springsource.org.aopalliance-1.0.0, ASM-4.0.

      Now the error I get is:

      Code:
      Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roby' defined in class path resource [greet.xml]:
      Initialization of bean failed; nested exception is java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V

      Comment


      • #4
        That is why you should use maven, ant+ivy or gradle to manage your dependencies.

        Not sure what the exception now is, seems to be a configuration or class error (cglib requires a no-arg constructor and non-final classes).

        Comment


        • #5
          Originally posted by robyonrails View Post
          Why are there a million of Spring dependencies that one developer has to look for? :\

          I've added references for the following JARs: aspectjweaver-1.6.11, cglib-2.2.2, com.springsource.org.aopalliance-1.0.0, ASM-4.0.

          Now the error I get is:

          Code:
          Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roby' defined in class path resource [greet.xml]:
          Initialization of bean failed; nested exception is java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
          change ASM-4.0 to ASM-3.3.1 ....

          that is work to me.

          Comment


          • #6
            Thanks so much for your solution! The error was fixed!

            Comment

            Working...
            X