Spring Aop“Around.class”找不到类别 [英] Spring Aop "Around.class" Class Not Found Exception

查看:158
本文介绍了Spring Aop“Around.class”找不到类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1095)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1040)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.springaoppractice.aop.AopMain.main(AopMain.java:12)

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1088)
    ... 13 more
Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
    at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.<clinit>(ReflectiveAspectJAdvisorFactory.java:74)
    at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.<init>(AnnotationAwareAspectJAutoProxyCreator.java:53)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 15 more

我无法弄清楚为什么我得到这个错误我的AspectJ Lib包括以下jar:

I can not figure out why am I getting this error my AspectJ Lib includes following jars:


  • aspectjrt.jar

  • aspectjweaver.jar

  • cglib-2.2.2.jar

  • aopalliance-1.0.jar

  • asm-common-3.3.1.jar

  • aspectjrt.jar
  • aspectjweaver.jar
  • cglib-2.2.2.jar
  • aopalliance-1.0.jar
  • asm-common-3.3.1.jar

这是我的主要方法:

package com.springaoppractice.aop;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.springaoppractice.aop.service.ShapeService;

public class AopMain {

    public static void main (String[] args){

        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        ShapeService shapeService = context.getBean("shapeService", ShapeService.class);
        System.out.println(shapeService.getCircle().getName());

    }
}

这是我的看点:

package com.springaoppractice.aop.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class LoggingAspect {

    @Before("execution(public String getName())")
    public void LoggingAdvice (){
        System.out.println("Logging advice initiazlied, get method is called!");
    }
}

继承我的ServiceClass:

package com.springaoppractice.aop.service;

import com.springaoppractice.aop.model.Circle;
import com.springaoppractice.aop.model.Triangle;

public class ShapeService {

    private Circle circle;
    private Triangle triangle;

    public Circle getCircle() {
        return circle;
    }
    public void setCircle(Circle circle) {
        this.circle = circle;
    }
    public Triangle getTriangle() {
        return triangle;
    }
    public void setTriangle(Triangle triangle) {
        this.triangle = triangle;
    }
}

以下是我的模特:

package com.springaoppractice.aop.model;

public class Circle {

    private String name;

    public String getName(){
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

package com.springaoppractice.aop.model;

public class Triangle {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

这是我的SPRING .XML

<?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"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <aop:aspectj-autoproxy/>

    <bean name="triangle" class="com.springaoppractice.aop.model.Triangle">
        <property name="name" value="TRIANGLE NAME" />
    </bean>

    <bean name="circle" class="com.springaoppractice.aop.model.Circle">
        <property name="name" value="CIRCLE NAME" />
    </bean>

    <bean name="shapeService" class="com.springaoppractice.aop.service.ShapeService" autowire="byName" />
    <bean name="loggingAspect" class="com.springaoppractice.aop.aspect.LoggingAspect" />



</beans>

添加到类路径的jar:

推荐答案

因为不正确的aopalliance jar,我遇到了同样的问题。
我之前使用的是aopalliance-alpha1.jar

So I was having the same issue due to incorrect aopalliance jar. What I had earlier was aopalliance-alpha1.jar

然后我将其更改为aopalliance-1.0.jar,您可以从 http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0

But then I changed it to aopalliance-1.0.jar which you can download from http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0

该计划正在为我工​​作。

The program is working for me.

这篇关于Spring Aop“Around.class”找不到类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆