我是靠谱客的博主 会撒娇饼干,最近开发中收集的这篇文章主要介绍The bean ‘llWebSocketHandler‘ could not be injected because it is a JDK dynamic proxy that implemen,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
摘要:在做Spring Boot、WebSockets整合的时候,出现了bean注入失败的问题,错误异常如下:
一:异常信息:
2018-08-10 11:44:50.072 WARN 20296 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'llWebSocketConfig': Unsatisfied dependency expressed through field 'llWebSocketHandler'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'llWebSocketHandler' is expected to be of type 'com.micai.spring.messaging.web.socket.LlWebSocketHandler' but was actually of type 'com.sun.proxy.$Proxy57'
2018-08-10 11:44:50.075 INFO 20296 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-08-10 11:44:50.287 INFO 20296 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-08-10 11:44:50.292 ERROR 20296 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'llWebSocketHandler' could not be injected as a 'com.micai.spring.messaging.web.socket.LlWebSocketHandler' because it is a JDK dynamic proxy that implements:
Action:
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
其中最重要的一句就是:
The bean 'llWebSocketHandler' could not be injected as a 'com.micai.spring.messaging.web.socket.LlWebSocketHandler' because it is a JDK dynamic proxy that implements:
二:解决过程:
我们知道:spring.proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。首先说明下proxy-target-class="true"和proxy-target-class="false"的区别,为true则是基于类的代理将起作用(需要cglib库),为false或者省略这个属性,则标准的JDK 基于接口的代理将起作用。
proxy-target-class在spring事务、aop、缓存这几块都有设置,其作用都是一样的。
所以要想解决上面的问题,只需要在application.properties文件中配置下spring.aop.proxy-target-class=true就行,这样LlWebSocketHandler类就可以被当做基于类的代理注入进来了。
以上就是对这个错误的分析过程。
最后
以上就是会撒娇饼干为你收集整理的The bean ‘llWebSocketHandler‘ could not be injected because it is a JDK dynamic proxy that implemen的全部内容,希望文章能够帮你解决The bean ‘llWebSocketHandler‘ could not be injected because it is a JDK dynamic proxy that implemen所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复