这个是我的maven依赖
这个是我的对象
另一个对象
切面类
测试类
求大神帮我顺便看看。问题出在哪里了?为什么老是出错
下面是出错的
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bfy' defined in file [D:\javaee\ZhujieBean\target\classes\com\AOP\Bigfy.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/annotation/OrderUtils
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.AOP.Fytest.main(Fytest.java:8)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/annotation/OrderUtils
at org.springframework.aop.aspectj.annotation.BeanFactoryAspectInstanceFactory.getOrder(BeanFactoryAspectInstanceFactory.java:121)
at org.springframework.aop.aspectj.annotation.LazySingletonAspectInstanceFactoryDecorator.getOrder(LazySingletonAspectInstanceFactoryDecorator.java:81)
at org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl.getOrder(InstantiationModelAwarePointcutAdvisorImpl.java:174)
at org.springframework.core.annotation.AnnotationAwareOrderComparator.getOrder(AnnotationAwareOrderComparator.java:50)
at org.springframework.core.OrderComparator.compare(OrderComparator.java:58)
at org.springframework.aop.aspectj.autoproxy.AspectJPrecedenceComparator.compare(AspectJPrecedenceComparator.java:81)
at org.springframework.aop.aspectj.autoproxy.AspectJPrecedenceComparator.compare(AspectJPrecedenceComparator.java:49)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator$PartiallyComparableAdvisorHolder.compareTo(AspectJAwareAdvisorAutoProxyCreator.java:132)
at org.aspectj.util.PartialOrder$SortObject.addDirectedLinks(PartialOrder.java:71)
at org.aspectj.util.PartialOrder.addNewPartialComparable(PartialOrder.java:93)
at org.aspectj.util.PartialOrder.sort(PartialOrder.java:129)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.sortAdvisors(AspectJAwareAdvisorAutoProxyCreator.java:77)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:91)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:347)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization
11 个解决方案
#1
这个是另一个切面类
#2
求大神帮忙看看。 感激不尽
#3
把spring-core换成4.1以上的 spring.xml里面上的声明也改成对应版本的试试看
#4
Error creating bean with name 'bfy' defined in file 你可以看下你的bean类是否注册
#5
话不多说,贴下我自己的:
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<!-- 指定自动搜索Bean组件、自动搜索切面类 -->
<context:component-scan base-package="org.crazyit.app.service
,org.crazyit.app.aspect">
<context:include-filter type="annotation"
expression="org.aspectj.lang.annotation.Aspect"/>
</context:component-scan>
<!-- 启动@AspectJ支持 -->
<aop:aspectj-autoproxy/>
</beans>
#6
切面:
被拦截类:
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.*;
/**
* Description:
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
// 定义一个切面
@Aspect
public class AuthAspect
{
// 匹配org.crazyit.app.service.impl包下所有类的、
// 所有方法的执行作为切入点
@Before("execution(* org.crazyit.app.service.impl.*.*(..))")
public void authority()
{
System.out.println("模拟执行权限检查");
}
}
被拦截类:
@Service("hello")
public class HelloImpl
{
// 定义一个简单方法,模拟应用中的业务逻辑方法
public void foo()
{
System.out.println("执行Hello组件的foo()方法");
}
// 定义一个addUser()方法,模拟应用中的添加用户的方法
public int addUser(String name , String pass)
{
System.out.println("执行Hello组件的addUser添加用户:" + name);
return 20;
}
}
#7
被拦截类2:
测试类:
@Service("world")
public class WorldImpl
{
// 定义一个简单方法,模拟应用中的业务逻辑方法
public void bar()
{
System.out.println("执行World组件的bar()方法");
}
}
测试类:
public class BeanTest
{
public static void main(String[] args)
{
// 创建Spring容器
ApplicationContext ctx = new
ClassPathXmlApplicationContext("beans.xml");
HelloImpl hello = ctx.getBean("hello" , HelloImpl.class);
hello.foo();
hello.addUser("孙悟空" , "7788");
WorldImpl world = ctx.getBean("world" , WorldImpl.class);
world.bar();
}
}
#8
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/annotation/OrderUtils.html
看你的报错信息是说这个类找不到,这个类是4.1以上的版本中才有的,所以你换到4.1以上版本试试,你的maven中的依赖版本不一致,有的包是4.0,AOP的包是4.3的所以这里可能就是问题的所在,换成统一的版本吧
看你的报错信息是说这个类找不到,这个类是4.1以上的版本中才有的,所以你换到4.1以上版本试试,你的maven中的依赖版本不一致,有的包是4.0,AOP的包是4.3的所以这里可能就是问题的所在,换成统一的版本吧
#9
Error:could not find the object
#10
确实是这个问题。真心感谢大神!!
#11
吃瓜。观摩观摩
#1
这个是另一个切面类
#2
求大神帮忙看看。 感激不尽
#3
把spring-core换成4.1以上的 spring.xml里面上的声明也改成对应版本的试试看
#4
Error creating bean with name 'bfy' defined in file 你可以看下你的bean类是否注册
#5
话不多说,贴下我自己的:
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<!-- 指定自动搜索Bean组件、自动搜索切面类 -->
<context:component-scan base-package="org.crazyit.app.service
,org.crazyit.app.aspect">
<context:include-filter type="annotation"
expression="org.aspectj.lang.annotation.Aspect"/>
</context:component-scan>
<!-- 启动@AspectJ支持 -->
<aop:aspectj-autoproxy/>
</beans>
#6
切面:
被拦截类:
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.*;
/**
* Description:
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
// 定义一个切面
@Aspect
public class AuthAspect
{
// 匹配org.crazyit.app.service.impl包下所有类的、
// 所有方法的执行作为切入点
@Before("execution(* org.crazyit.app.service.impl.*.*(..))")
public void authority()
{
System.out.println("模拟执行权限检查");
}
}
被拦截类:
@Service("hello")
public class HelloImpl
{
// 定义一个简单方法,模拟应用中的业务逻辑方法
public void foo()
{
System.out.println("执行Hello组件的foo()方法");
}
// 定义一个addUser()方法,模拟应用中的添加用户的方法
public int addUser(String name , String pass)
{
System.out.println("执行Hello组件的addUser添加用户:" + name);
return 20;
}
}
#7
被拦截类2:
测试类:
@Service("world")
public class WorldImpl
{
// 定义一个简单方法,模拟应用中的业务逻辑方法
public void bar()
{
System.out.println("执行World组件的bar()方法");
}
}
测试类:
public class BeanTest
{
public static void main(String[] args)
{
// 创建Spring容器
ApplicationContext ctx = new
ClassPathXmlApplicationContext("beans.xml");
HelloImpl hello = ctx.getBean("hello" , HelloImpl.class);
hello.foo();
hello.addUser("孙悟空" , "7788");
WorldImpl world = ctx.getBean("world" , WorldImpl.class);
world.bar();
}
}
#8
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/annotation/OrderUtils.html
看你的报错信息是说这个类找不到,这个类是4.1以上的版本中才有的,所以你换到4.1以上版本试试,你的maven中的依赖版本不一致,有的包是4.0,AOP的包是4.3的所以这里可能就是问题的所在,换成统一的版本吧
看你的报错信息是说这个类找不到,这个类是4.1以上的版本中才有的,所以你换到4.1以上版本试试,你的maven中的依赖版本不一致,有的包是4.0,AOP的包是4.3的所以这里可能就是问题的所在,换成统一的版本吧
#9
Error:could not find the object
#10
确实是这个问题。真心感谢大神!!
#11
吃瓜。观摩观摩