0819 개발일지

Yesol Lee·2022년 8월 19일
0

개발일지 - 2022

목록 보기
119/187

오늘 한 일

  • 뉴스레터 최종 검수
  • 사이드 프로젝트 : 어제 발견한 에러 해결, H2 JPA로 연결 완료
  • 오라클 완전 삭제
  • jdk, eclipse 없는 에러 해결

사이드 프로젝트

에러해결 : repository 연결 실수

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.ticktack.practice224.service.UserServiceIntegrationTest': Unsatisfied dependency expressed through field 'userRepo'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ticktack.practice224.repository.user.MemoryUserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

  • 문제 : 통합테스트용 파일을 생성해서 실행하니 이제 사용하지 않는 MemoryRepository를 자꾸 생성하지 못한다고 함
  • 원인 : test파일의 repo를 구현체가 아닌 인터페이스로 바꿔주어야 하는데 깜빡했다.
  • 해결 : 구현체를 인터페이스로 변경
// UserServiceIntegrationTest.java
@Autowired UserRepository userRepo; // 여기가 MemoryUserRepository로 되어있었다

에러해결 : SQL

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
...
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "USER0.JOINED_AT" not found; SQL statement:
select user0
.id as id11, user0.joined_at as joined_a2_1, user0.name as name3_1 from user user0 where user0.name=? [42122-200]

  • 문제 : User 테이블에서 JOINED_AT를 찾을 수 없다고 함
  • 원인 : java와 DB의 테이블 컬럼명이 달라서 생김
  • 해결 : H2 DB의 테이블 컬럼명을 java와 맞게 변경해주었다.

에러 : assertion 예상값이 의도와 다름

org.opentest4j.AssertionFailedError:
expected: true
but was: false
...
at com.ticktack.practice224.service.PostServiceIntegrationTest.게시물삭제(PostServiceIntegrationTest.java:119)

  • 문제 : 통합테스트 시 게시물 삭제 후 삭제처리한 게시물이 존재하는지 여부를 boolean으로 받아 비교하는 assertion인데, 결과가 자꾸 다르게 나온다.
  • 원인 : 1차 문제는 expect하는 정답값과 비교값의 자리를 바꿔서 넣은 것인데, 제자리로 해도 두 값이 다르다는 것은 변하지 않는다. 아직 해결 못함
  • 특이점 : 통합테스트는 다르다고 나오는데, 실제 돌려보면 DB에서 삭제가 잘 되고 있다. 뭔가 테스트코드를 잘못 짠 듯...

에러 해결: 생성 시 createdAt, updatedAt이 null

  • repository에서 생성, 수정 시 날짜 입력 코드 추가
  • 수정 시 최초 작성일이 null이 되는 것은 좀 더 복잡한 문제였다.
// JpaPostRepository.java
@Override
public Post save(Post post) {
	post.setCreatedAt(new Date());
	post.setUpdatedAt(post.getCreatedAt());
	em.persist(post);
	return post;
}
@Override
public Post update(Post post) {
	post.setUpdatedAt(new Date());
	em.merge(post);
	return post;
}

에러 해결 : 수정 시 createdAt null 되는 원인

  1. html에서 input-hidden으로 createdAt을 넘겨주는 것 누락됨
  2. controller에서 PostForm으로 받은 정보를 Post에 넣는 것 누락
  • 두 가지를 전부 바꿔주었더니 html에서 받은 date가 string형식이라 문제가 되었다.

에러 해결 : date format 에러

[Error] datetime format java.text.ParseException: Unparseable date

Java : Unparseable date 에러

  • SimpleDateFormat 클래스를 이용해 string으로 들어온 createdAt 정보를 Date로 바꾼 후 넘겨주었다.
// PostController.java
@PostMapping("/posts/update")
public String updatePost(PostForm form) {
	
	Post post = new Post();
	...
	
	// 날짜 string->Date
//		post.setContent(form.getCreatedAt());
	post.setCreatedAt(stringToDate(form.getCreatedAt()));
	
	postService.updatePost(post);
	
	return "redirect:/homes/selectHome?homeId=" + form.getHomeId();
}

private Date stringToDate (String date) {
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
	Date parsedDate = new Date();
	try {
		parsedDate = formatter.parse(date);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return parsedDate;
}

오라클 완전 삭제

에러 해결 : 이클립스 실행 시 jdk 찾지 못함

A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations:
C:\Program Files\eclipse\jre\bin\javaw.exe
javaw.exe in your current PATH"

eclipse 실행 시 vm 찾지 못하는 에러

  • eclipse.ini 파일 안 -vm 경로 작성 (-vmargs 섹션 앞에 작성)

에러 해결 : h2 액세스가 거부되었습니다

  • H2 console(commandLine) 띄우면 자바 버전이 없다는 말이 뜨면서 접속불가
  • JAVA_HOME 환경변수 없으면 에러나는 듯
  • JAVA_HOME을 시스템 변수에 추가해주어야 하는데 사용자 변수에 추가해서 일반 cmd창에서 자바 버전을 확인할 수 없었다.
profile
문서화를 좋아하는 개발자

0개의 댓글