반응형

Repository 생성 후 테스트하는 과정에서 에러가 발생했다.

 

에러 내용

- Time 테이블을 찾을 수 없다는 에러가 테스트 메소드에서 발생

- 자세한 내용 확인을 위해 클래스의 에러 확인

- "Error executing DDL" 에러 발생 확인

 

원인

- "Error executing DDL"가 발생한 원인을 검색해 보니 예약된 문구를 컬럼으로 사용하면 발생한다는걸 확인

@Getter
@NoArgsConstructor
@Entity
public class Time {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String group;
    private String subject;
    private LocalDateTime date;
    private Duration duration;

    @Builder
    public Time(String groupName, String subject, LocalDateTime date, Duration duration) {
        this.group = groupName;
        this.subject = subject;
        this.date = date;
        this.duration = duration;
    }
}

- 4개의 컬럼 중 하나가 문제가 되므로 컬럼 이름을 변경해 주어야 한다.

 

해결

- 결과적으로는 group이 sql에 예약되어 있어 발생

- group을 groupName으로 변경하여 해결

 

@Getter
@NoArgsConstructor
@Entity
public class Time {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String groupName; // 수정
    private String subject;
    private LocalDateTime date;
    private Duration duration;

    @Builder
    public Time(String groupName, String subject, LocalDateTime date, Duration duration) {
        this.groupName = groupName;
        this.subject = subject;
        this.date = date;
        this.duration = duration;
    }
}

 

반응형

'ETC > Spring' 카테고리의 다른 글

[error] Failed to load ApplicationContext  (1) 2023.05.27
반응형

TDD 를 적용하여 개발 하던 중 에러가 발생했다.

 

환경

- Spring Boot 2.7.12

- JDK 11

- JUnit 5

 

 

테스트 코드

@SpringBootTest
public class TimeRepositoryTest {

    @Autowired
    TimeRepository timeRepository;
    @Test
    public void save() {
        Time time = Time.builder()
                .group("test")
                .subject("test")
                .date(LocalDateTime.now())
                .duration(Duration.ofMinutes(19))
                .build();

        Time savedTime= timeRepository.save(time);
        assertThat(savedTime).isEqualTo(time);
    }
}

 

발생 에러

- java.lang.IllegalStateException: Failed to load ApplicationContext

 

- 발생한 테스트 메소드에서는 정확한 원인을 알기 어려웠다.

- 테스트 클래스를 클릭해서 로그를 보니 원인을 파악할 수 있었다.

실제 원인

- 아래 캡처 내용 처럼 Datasource 설정에 실패 한 것이다.

- 해결책도 제시해 준다. 임베디드 데이터베이스를 사용하면 해결이 될 것으로 보인다.

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

 

해결

- 해당 에러에 대한 해결은 H2 를 설치하면서 해결 하였다.

dependencies {
	// H2
	implementation 'com.h2database:h2'
}
반응형

'ETC > Spring' 카테고리의 다른 글

[error] Table not found / Error executing DDL  (0) 2023.05.27

+ Recent posts