今天写代码时遇到一个问题,给AService配置事务后运行报错:
Unsatisfied dependency expressed through field 'aService': Bean named 'aService' is expected to be of type [AService] but was actually of type [com.sun.proxy.$Proxy64];
排查发现AService的注入方式是AService aService实体类注入,而不是IAService aService接口注入。
spring的DI是面向接口的,所以在配置事务后需要使用接口注入。

本文探讨了在Spring框架中配置事务时遇到的问题,即实体类注入而非接口注入导致的类型不匹配错误,并阐述了解决方案。
173万+

被折叠的 条评论
为什么被折叠?



