gpt4 book ai didi

java - Spring 错误 : BeanNotOfRequiredTypeException

转载 作者:搜寻专家 更新时间:2023-11-01 01:18:50 25 4
gpt4 key购买 nike

我的 Controller 包含以下注释:

@Resource(name="userService")
private UserDetailsServiceImpl userService;

服务本身具有以下内容:

@Service("userService")
@Transactional
public class UserDetailsServiceImpl implements UserDetailsService {

@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;

但是我在启动时收到以下错误:

Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDetailsServiceImpl' must be of type [myapp.service.UserDetailsServiceImpl], but was actually of type [$Proxy19]

最佳答案

应该是

@Resource(name="userService")
private UserDetailsService userService;

Spring使用接口(interface)类型进行依赖注入(inject),而不是实现类型

关于java - Spring 错误 : BeanNotOfRequiredTypeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6586727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com