记录:Need to invoke method ‘insertUser‘ declared on target class ‘XxxServiceImpl‘...解决方案

Posted bug菌¹

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了记录:Need to invoke method ‘insertUser‘ declared on target class ‘XxxServiceImpl‘...解决方案相关的知识,希望对你有一定的参考价值。

一、前文🔥

 👨‍🎓作者:bug菌

✏️博客:CSDN掘金

💌公众号:猿圈奇妙屋

🚫特别声明:原创不易,转载请附上原文出处链接和本文声明,谢谢配合。

🙏版权声明:文章里可能部分文字或者图片来源于互联网或者百度百科,如有侵权请联系bug菌处理。

二、环境说明🔥

环境:springboot2.3.1.REALSE + mysql5.6 + jdk1.8

三、报错分析🔥

如下是具体报错内容全文,大家可以看看:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'sysMenuService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysMenuServiceImpl': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysUserServiceImpl' defined in file [C:\\Users\\86157\\Desktop\\review-server\\target\\classes\\com\\example\\review\\service\\impl\\SysUserServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Need to invoke method 'insertUser' declared on target class 'SysUserServiceImpl', but not found in any interface(s) of the exposed proxy type. Either pull the method up to an interface or switch to CGLIB proxies by enforcing proxy-target-class mode in your configuration.
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1304) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1224) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	... 20 common frames omitted

        不会还真的有小伙伴听我的话,在看上述完整报错信息吧,哈哈哈哈。如上这么内容繁多,其实重点看这块就可以,大家请看(我够意思吧!)

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating
 bean with name 'sysMenuServiceImpl': Unsatisfied dependency expressed through field
 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sysUserServiceImpl' defined in file 
[C:\\Users\\86157\\Desktop\\review-server\\target\\classes\\com\\example\\review\\service\\impl\\SysUserServiceImpl.class]:
 Initialization of bean failed; nested exception is java.lang.IllegalStateException: Need
 to invoke method 'insertUser' declared on target class 'SysUserServiceImpl', but not found
 in any interface(s) of the exposed proxy type. Either pull the method up to an interface
 or switch to CGLIB proxies by enforcing proxy-target-class mode in your configuration.

        据报错描述,是说这个SysUserServiceImpl 实现类没有找到?很离谱,明明我看target文件夹也编译加载上了啊,怎么这个类会找不到呢?令我百思不得其解,时间过去了半个钟头,终于被我发现了问题所在!就是这个定时任务捣的鬼。

        我这是一个springboot项目,在一个接口的实现类里定义了一个异步定时任务,由于不想暴露出去,便没有在接口里面没有定义这个方法,然后项目启动就报错,在公开的接口方法中找不到这个方法,所以创建bean失败。

        所以替你们分析到这一步,你们知道咋解决该问题了么?

四、解决方案🔥

        如果你也是跟我一样的情况,那就直接在你的接口中加上这个方法,然后通过实现类@Override 注解去实现这个接口,bug立马解决!

具体添加可见我如下截图,仅供大家参考:

ISysUserService.java

SysUserServiceImpl.java

        然后你再重启项目,如果还存在该问题,请文下评论告诉我!我一定帮你看~ 

 ... ...

        好啦,以上就是解决该报错的所有内容啦,你们学废了么?如果对你有所帮助,还请不要忘记给bug菌[三连支持]哟。如果想获得更多的学习资源或者想和更多的技术爱好者一起交流,可以关注我的公众号『猿圈奇妙屋』,后台回复关键词领取学习资料、大厂面经、面试模板等海量资源,就等你来拿。

五、文末🔥

        如果你还想要学习更多,小伙伴们大可关注bug菌专门为你们创建的专栏《bug调优》,都是我一手打下的江山,持续更新中,希望能帮助到更多小伙伴们。

       我是bug菌,一名想走👣出大山改变命运的程序猿。接下来的路还很长,都等待着我们去突破、去挑战。来吧,小伙伴们,我们一起加油!未来皆可期,fighting!

最后送大家两句话,与诸君共勉!


☘️做你想做的人,没有时间限制,只要愿意,什么时候都可以start,

🍀你能从现在开始改变,也可以一成不变,这件事,没有规矩可言,你可以活出最精彩的自己。


​​​

💌如果文章对您有所帮助,就请留下您的吧!(#^.^#);

💝如果喜欢bug菌分享的文章,就请给bug菌点个关注吧!(๑′ᴗ‵๑)づ╭❤~;

💗如果对文章有任何疑问,还请文末留言或者加群吧【QQ交流群:708072830】;

💞鉴于个人经验有限,所有观点及技术研点,如有异议,请直接回复参与讨论(请勿发表攻击言论,谢谢);

💕版权声明:原创不易,转载请附上原文出处链接和本文声明,版权所有,盗版必究!!!谢谢。

以上是关于记录:Need to invoke method ‘insertUser‘ declared on target class ‘XxxServiceImpl‘...解决方案的主要内容,如果未能解决你的问题,请参考以下文章

Dubbo服务调用Failed to invoke the method错误记录

添加@ControllerAdvice后报错 Failed to invoke @ExceptionHandler method

bubbo调用Failed to invoke remote method异常解决

Shiro报异常org.apache.shiro.authz.AuthorizationException: Not authorized to invoke method:

java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.database.sqlite异常

dubbo异常: Failed to invoke the method getXXXX in the service 异常解决方案