본문 바로가기
Programming/Spring Boot

"java.lang.IllegalStateException: Failed to introspect Class" 오류 해결 방법

by 돌방로그 2023. 2. 24.


IdClass 정의 및 JPARepository 상속받은 후 쿼리 메소드 추가시 발생하는 오류

상황

Spring Boot 프로젝트에서 복합키(Composite Primary Key)를 사용하기 위해 @IdClass 어노테이션관련 코드 구현 후, Repository에 쿼리 메소드 추가 후 빌드시 발생한 오류입니다.

오류 메세지는 대표적으로 4가지 정도 추출할 수 있었으나 구글링한 결과 제 상황과 모두 일치하지 않는 상황이었습니다.

 

오류 메세지

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminUserInformationController': Unsatisfied dependency expressed through field 'adminUserPasswordService': Error creating bean with name 'adminUserPasswordService' defined in file [C:\Users\SYP\Git\toyproject\backend\web-api-server\out\production\classes\com\logsjejustone\webapiserver\user\service\AdminUserPasswordService.class]: Post-processing of merged bean definition failed at ... 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminUserPasswordService' defined in file [C:\Users\SYP\Git\toyproject\backend\web-api-server\out\production\classes\com\logsjejustone\webapiserver\user\service\AdminUserPasswordService.class]: Post-processing of merged bean definition failed at ...

Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.logsjejustone.webapiserver.user.service.AdminUserPasswordService] from ClassLoader [org.springframework.boot.devtools.restart.classloader.RestartClassLoader@13339da] at ...

Caused by: java.lang.NoClassDefFoundError: com/logsjejustone/webapiserver/user/repository/AdminUserPasswordRepository at ...

Caused by: java.lang.ClassNotFoundException: com.logsjejustone.webapiserver.user.repository.AdminUserPasswordRepository at ...

 

주요한 오류 메세지만 추출하자면 아래와 같습니다.

1. Unsatisfied dependency expressed through field

2. Post-processing of merged bean definition failed

3. Error creating bean with name

4. Failed to introspect Class

 

코드

Repository

public interface AdminUserPasswordRepository extends JpaRepository<AdminUserPassword, AdminUserPasswordKey> {
    AdminUserPassword findAllByOrderByEmployeeNoDesc();
    ...
}

 

Entity / Domain

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name="AdminUserPasswordHistory")
@IdClass(AdminUserPassword.class)
public class AdminUserPassword {
    @Id
    @NotNull
    @Column(length = 6)
    private String employeeNo;

    @Id
    @NotNull
    private Integer no;

    @NotNull
    @Column(length = 6)
    private String registerEmployeeNo;

    ...
}

 

Key Class

@Getter
@Setter
@Data
public class AdminUserPasswordKey implements Serializable {
    private String employeeNo;
    private Integer no;
}

 

 

원인

@IdClass에는 PK 특성을 지닌 컬럼이 정의된 클래스 명칭을 지정해야 하나 Entity/Domain 클래스 자체 명칭을 기입하고 있어서 발생한 오류였습니다.

IntelliJ의 자동 텍스트 완성 기능을 이용하다보니 발생한 오탈자 오류였습니다.

 

 

해결 방법

@IdClass 어노테이션으로 지정된 class는 PK 특성을 지니는 ID Class로 정의한 클래스명이 위치하도록 수정하여 해결하였습니다.

즉, 아래와 같이 수정하니 오류가 해결되었습니다.

  • @IdClass(AdminUserPassword.class) → @IdClass(AdminUserPasswordKey.class)

 

 

변경된 코드

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name="AdminUserPasswordHistory")
@IdClass(AdminUserPasswordKey.class)  // ERROR REASON
public class AdminUserPassword {
    @Id
    @NotNull
    @Column(length = 6)
    private String employeeNo;

    @Id
    @NotNull
    private Integer no;

    @NotNull
    @Column(length = 6)
    private String registerEmployeeNo;
    
    ...
}

 


 

댓글