본문 바로가기

카테고리 없음

[Spring] [error] nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userServiceImpl' is expected to be of type 'kr.or.connect.security.service.UserServiceImpl' but was actually of type 'com.sun.proxy.$Prox..

Error creating bean with name 'userController' defined in file [/Users/yoon/Code/WebBackend/reservation/target/reservation/WEB-INF/classes/kr/or/connect/security/controller/UserController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userServiceImpl' is expected to be of type 'kr.or.connect.security.service.UserServiceImpl' but was actually of type 'com.sun.proxy.$Proxy29'

 

@RequiredArgsConstructor 또는 @Autowired로 어떤 클래스에 대한 의존성 주입을 할 때,

인터페이스와 구체 클래스로 구성되어있는 클래스라면, 반드시 "인터페이스"로 의존성 주입을 해야 한다.

 

// 오류 발생 코드
@Controller
@RequestMapping(path = "/members")
@RequiredArgsConstructor
public class UserController {
    private final UserServiceImpl userService;
    private final PasswordEncoder passwordEncoder;
    

// 오류 수정 코드
@Controller
@RequestMapping(path = "/members")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;
    private final PasswordEncoder passwordEncoder;