Announcement Announcement Module
Collapse
No announcement yet.
Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor

    Hi,

    I'm learning AOP concepts.

    I had written a program using the AOP concepts.

    I got the following exception.


    Code:
    Exception in thread "main" 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.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'selectAll' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'selectAll': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:630)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at test.test_pjt.MainApp.main(MainApp.java:10)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'selectAll' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'selectAll': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:616)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
    	... 17 more


    Code looks as follows:
    main.java
    Code:
    package test.test_pjt;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import test.test_pjt.Student;
    public class MainApp {
     
    	public static void main(String[] args){
    
    		ApplicationContext context = new ClassPathXmlApplicationContext("Bean.xml");
    		
    		Student st = (Student) context.getBean("student");
    		
    		st.getName();
    		st.getAge();
    	}
    }
    Logging.java
    Code:
    @Aspect
    public class Logging {
    
    	@Pointcut("exectuion(* test.test_pjt.*.*(..))")
    	private void selectAll(){}
    	
    	@Before("selectAll()")
    	public void beforeAdvice(){
    		System.out.println("going to set student profile");
    	}
    	
    	@After("selectAll()")
    	public void afterAdvice() {
    		System.out.println("After setting up student profile");
    	}
    	
    	@AfterReturning(pointcut = "selectAll()", returning="retVal")
    	public void afterReturningAdvice(Object retVal) {
    		System.out.println("Returning :"+retVal.toString());
    	}
    	
    	@AfterThrowing(pointcut = "selectAll()", throwing="ex")
    	public void afterThrowingAdvice(IllegalArgumentException le) {
    		System.out.println("There has been an exception : "+le.toString());
    	}
    	
    }
    STUDENT.JAVA

    Code:
    package test.test_pjt;
    
    public class Student {
    
    	private Integer age;
    	private String name;
    	
    	public Integer getAge() {
    		return age;
    	}
    	public void setAge(Integer age) {
    		this.age = age;
    	}
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	
    	public void printThrowableExcetion() {
    		System.out.println("Exception raise : ");
    		throw new IllegalArgumentException();
    	}
    	
    }

    BEAN.XML

    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">
    		
    
        <aop:config>
        
          <aop:aspect id="log" ref="logging">
          
          <aop:pointcut id="selectAll" expression="execution(* test.test_pjt.*.*(..))" />
          
          <aop:before pointcut-ref="selectAll" method="beforeAdvice"/>
          
          <aop:after pointcut-ref="selectAll" method="afterAdvice"/>
          
          <aop:after-returning pointcut-ref="selectAll" returning="retVal" method="afterReturningAdvice"/>
          
          <aop:after-throwing pointcut-ref="selectAll" throwing="ex" method="afterThrowingAdvice"/>
          
          </aop:aspect>
        
        </aop:config>
    
    	
    	<bean id="student" class="test.test_pjt.Student"> 
    
    	 <property name="name" value="avi!"/>
    	 
    	 <property name="age" value="25"/> 
     
        </bean> 
     
        <bean id="logging" class="test.test_pjt.Logging"></bean>
     </beans>
    Last edited by avinash.madireddy; Nov 5th, 2012, 04:23 AM.

  • #2
    Include the proper jars in your application...

    Also why are you using annotations, those are useless as you are also using xml.. Use either one, not both.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      Include the proper jars in your application...

      Also why are you using annotations, those are useless as you are also using xml.. Use either one, not both.

      K. I'm using XML schema based annotation.

      Still i'm getting same exception.

      You can find my pom file regarding Jar's i used.

      Code:
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
      
        <groupId>test</groupId>
        <artifactId>test_pjt</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
      
        <name>test_pjt</name>
        <url>http://maven.apache.org</url>
      
        <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
      
        <dependencies>
        <dependency>
      	<groupId>org.springframework</groupId>
      	<artifactId>spring-web</artifactId>
      	<version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
      	<groupId>org.aspectj</groupId>
      	<artifactId>aspectjtools</artifactId>
      	<version>1.6.2</version>
        </dependency>
        <dependency>
      	<groupId>aspectj</groupId>
      	<artifactId>aspectjrt</artifactId>
      	<version>1.5.4</version>
        </dependency>
        <dependency>
      	<groupId>aspectj</groupId>
      	<artifactId>aspectjweaver</artifactId>
      	<version>1.5.4</version>
         </dependency>
                            
         <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
          </dependency>
        </dependencies>
      </project>

      Comment


      • #4
        You are mxing aspectj versions don't... Either use 1.6 or 1.5 don't mix both...

        K. I'm using XML schema based annotation.
        Huh?1 I don't get you... Either use the aspectj annotations and use aop:aspectj-autoproxy or don't use aspectj annotations and use xml...

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          You are mxing aspectj versions don't... Either use 1.6 or 1.5 don't mix both...


          Huh?1 I don't get you... Either use the aspectj annotations and use aop:aspectj-autoproxy or don't use aspectj annotations and use xml...

          i used the aspectj annotations and <aop:aspectj-autoproxy/>.

          still i'm getting the exception

          Code:
          Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'student' defined in class path resource [Bean.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.IllegalStateException: Throwing argument name 'ex' was not bound in advice arguments
          Can you refer my pom.xml and tell me weather i'm using correct jar's.
          Last edited by avinash.madireddy; Nov 5th, 2012, 07:19 AM.

          Comment


          • #6
            For AOP we need three jars, namely:

            aspectjrt.jar, aspectjweaver.jar, aspectj.jar.

            in my pom file i used them as follows:

            Code:
            <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
              <modelVersion>4.0.0</modelVersion>
            
              <groupId>test</groupId>
              <artifactId>test_pjt</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <packaging>jar</packaging>
            
              <name>test_pjt</name>
              <url>http://maven.apache.org</url>
            
              <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
              </properties>
            
              <dependencies>
              <dependency>
            	<groupId>org.springframework</groupId>
            	<artifactId>spring-web</artifactId>
            	<version>3.1.2.RELEASE</version>
              </dependency>
              <dependency>
            	<groupId>org.aspectj</groupId>
            	<artifactId>aspectjtools</artifactId>
            	<version>1.5.4</version>
             </dependency>
            
             <dependency>
            	<groupId>aspectj</groupId>
            	<artifactId>aspectjrt</artifactId>
            	<version>1.5.4</version>
             </dependency>
                         
              <dependency>
            	<groupId>aspectj</groupId>
            	<artifactId>aspectjweaver</artifactId>
            	<version>1.5.4</version>
              </dependency>
                        
              
               <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>3.8.1</version>
                  <scope>test</scope>
                </dependency>
              </dependencies>
            </project>

            Comment


            • #7
              still i'm getting the exception
              No your not.. (Why do people never READ the stacktrace)... You have a different stacktrace and this indicates a problem with your pointcut binding (it expects a method argument named ex and it there isn't one)....

              Comment


              • #8
                Originally posted by Marten Deinum View Post
                No your not.. (Why do people never READ the stacktrace)... You have a different stacktrace and this indicates a problem with your pointcut binding (it expects a method argument named ex and it there isn't one)....
                The problem is solved.
                I included the "cglib" jar. CGLIB Is Required To Process @Configuration Classes.
                <dependency>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
                <version>2.2</version>
                </dependency>

                Comment

                Working...
                X