使用Spring加载Dubbo的配置文件(xml)时报错,哪位大神帮忙解答啊

WARN ClassPathXmlApplicationContext:551 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.zhanglv.user.service.UserService': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/framework/AopProxyUtils

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.zhanglv.user.service.UserService': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/framework/AopProxyUtils
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.zhanglv.myTest.MainOfTest1.main(MainOfTest1.java:14)
Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AopProxyUtils
    at org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:105)
    at org.springframework.context.support.AbstractApplicationContext.addApplicationListener(AbstractApplicationContext.java:494)
    at org.springframework.context.support.ApplicationListenerDetector.postProcessAfterInitialization(ApplicationListenerDetector.java:78)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    ... 11 more

 

检查一下com.zhanglv.user.service.UserService对应配置的SQL语句有问题。

你这不是很明显吗,第一个创建 bean出错,查看是不是单词写错或者名称重复。 第二个NoClassDefFoundError 查看编译候得文件里面有没有对应类,没有的话 clean或这几删除了重新编译

楼主您好!请问是使用的Maven管理项目吗?这个异常可能是没有引入 Spring 的 AOP 组件导致的,可以在你项目的 pom.xml 中添加以下依赖试试:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>5.3.6</version>
</dependency>

注意:以上是Spring5对应的版本,如果你使用的是Spring4,最好换成相对应的4.x系列版本,跟你项目中使用的 Spring 版本一致最好。

怎么看自己使用的Spring版本?如果是使用 IDEA 开发工具,可以全局搜索 ApplicationContext 关键词,然后定位到该类所在jar包的位置,就可以看到版本了,如下图所示:

要查看Spring AOP的其他版本,可以到Maven中央仓库地址:https://mvnrepository.com/artifact/org.springframework/spring-aop

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!

速戳参与调研>>>https://t.csdnimg.cn/Kf0y