为什么会创建customerDao错误

正在回答

登陆购买课程后可参与讨论,去登陆

11回答

同学你好,同学在ApplicationContext2.xml中配置了后置通知,环绕通知等通知,但是在MyAspectXml类中,并没有写对应的方法,无法调用对应的方法,所以报错。这里建议同学要么将MyAspectXml类中所有的通知方法补全,如:

http://img1.sycdn.imooc.com//climg/5cbef9c000015fb609080683.jpg

要么去掉applicationContext2.xml中配置的切面的信息,如:

http://img1.sycdn.imooc.com//climg/5cbefa050001f52611040496.jpg

两者选择一个即可正常运行。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

好帮手慕阿满 2019-04-23 18:47:27

同学你好,建议同学去掉如下的注释再试试。

http://img1.sycdn.imooc.com//climg/5cbeed100001689708510347.jpg

祝:学习愉快~

  • 提问者 我要跳槽 #1
    还是不得行。。。
    2019-04-23 18:58:20
  • 好帮手慕阿莹 回复 提问者 我要跳槽 #2
    报错的信息是否有变化呢?还是原来的报错吗?祝学习愉快
    2019-04-23 19:18:45
提问者 我要跳槽 2019-04-23 17:35:23

<?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.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--XML的配置方式完成AOP的开发===============-->
    <!--配置目标类=================-->
    <bean id="customerDao" class="com.aspectJ.demo2.CustomerDaoImpl"/>

    <!--配置切面类-->
    <bean id="myAspectXml" class="com.aspectJ.demo2.MyAspectXml"/>

    <!--aop的相关配置=================-->
    <aop:config>
        <!--配置切入点-->
        <aop:pointcut id="pointcut1" expression="execution(* com.aspectJ.demo2.CustomerDao.save(..))"/>
      <!--   <aop:pointcut id="pointcut2" expression="execution(* com.aspectJ.demo2.CustomerDao.update(..))"/>
        <aop:pointcut id="pointcut3" expression="execution(* com.aspectJ.demo2.CustomerDao.delete(..))"/>
        <aop:pointcut id="pointcut4" expression="execution(* com.aspectJ.demo2.CustomerDao.findOne(..))"/>
        <aop:pointcut id="pointcut5" expression="execution(* com.aspectJ.demo2.CustomerDao.findAll(..))"/> -->
        <!--配置AOP的切面-->
        <aop:aspect ref="myAspectXml">
            <!--配置前置通知-->
            <aop:before method="before" pointcut-ref="pointcut1"/>
            <!--配置后置通知-->
            <aop:after-returning method="afterReturing" pointcut-ref="pointcut2" returning="result"/>
            <!--配置环绕通知-->
            <aop:around method="around" pointcut-ref="pointcut3"/>
            <!--配置异常抛出通知-->
            <aop:after-throwing method="afterThrowing" pointcut-ref="pointcut4" throwing="e"/>
            <!--配置最终通知-->
            <aop:after method="after" pointcut-ref="pointcut5"/>
        </aop:aspect>

    </aop:config>
</beans>



提问者 我要跳槽 2019-04-23 15:58:25
  • 建议同学将applicationContext2.xml的内容贴一下。记得贴在回答中,选择代码语言。祝:学习愉快~
    2019-04-23 17:18:13
  • 提问者 我要跳槽 回复 好帮手慕阿满 #2
    老师已贴在回答中了
    2019-04-23 17:36:50
好帮手慕阿满 2019-04-23 14:43:21

同学你好,问一下同学CustomerDaoImpl类是在com.aspectJ.demo2包下的,没有imooc.这个包吗?建议同学检查一下。

祝:学习愉快~

  • 提问者 我要跳槽 #1
    对,我没有imooc这个包,看我的回复
    2019-04-23 15:58:06
提问者 我要跳槽 2019-04-23 09:03:18
好帮手慕阿满 2019-04-22 18:45:29

同学你好,问一下同学pom文件中是否存在如下的依赖:

http://img1.sycdn.imooc.com//climg/5cbd9b0100014aa004380126.jpg

如果没有建议同学添加一下。

另外建议同学检查一下applicationContext2.xml的位置是否在resources文件下。

祝:学习愉快~

  • 提问者 我要跳槽 #1
    老师你看下
    2019-04-23 09:02:48
  • 提问者 我要跳槽 #2
    老师,都是没问题的
    2019-04-23 09:04:11
提问者 我要跳槽 2019-04-22 15:27:14
好帮手慕阿满 2019-04-22 15:19:22

同学你好,同学的报错信息好像没有贴完整。建议同学将完整的错误信息贴一下。

祝:学习愉快~

  • 提问者 我要跳槽 #1
    老师放在回复里面了
    2019-04-22 15:27:33
提问者 我要跳槽 2019-04-22 11:23:03

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerDao' defined in class path resource [applicationContext2.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#1': Cannot create inner bean '(inner bean)#7cc0cdad' 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)#7cc0cdad': Cannot create inner bean '(inner bean)#4c583ecf' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#4c583ecf': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Unable to locate method [afterReturing] on bean [myAspectXml]
四月 22, 2019 11:21:23 上午 org.springframework.test.context.TestContextManager prepareTestInstance
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2133c8f8] to prepare test instance [com.aspectJ.demo2.SpringDemo2@55141def]
java.lang.IllegalStateException: Failed to load ApplicationContext

好帮手慕珊 2019-04-20 18:00:41

你好!控制台还有其他的报错提示吗,建议贴完整,从当前的内容看没有什么问题,需要通过完整报错去筛查。祝学习愉快!

  • 提问者 我要跳槽 #1
    老师你看下,我粘贴的错误信息,第一行太长了,不好截图
    2019-04-22 14:18:59
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师