-
099. Spring JPA 에러IT 공부방 [기본지식 정리]/Spring JPA 2025. 4. 14. 15:13
1. MySQL 인증 시, Public Key Retrieval not allowed
본인 mysql 패스워드 해쉬 방식이 caching_sha2_password 라면
> application.properties에 "&allowPublicKeyRetrieval=true" 추가
spring.datasource.url=jdbc:mysql://218.233.220.216:43030/myapp?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true2. org.springframework.dao.DataIntegrityViolationException: could not execute statement
[Column 'age' cannot be null]
> open build/reports/tests/test/index.html > 해당 파일 브라우저로 열어서 확인
> DB 제약조건에 not null 이므로 값을 추가해준다.
3. spring.jpa.hibernate.ddl-auto=update # (우측에 붙이면 주석처리가 아니라 같은 문자열로 인식됨.)
AptalkApplicationTests > contextLoads() FAILED java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:180 Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1818 Caused by: jakarta.persistence.PersistenceException at AbstractEntityManagerFactoryBean.java:431 Caused by: java.lang.IllegalArgumentException at Action.java:305
4. 401 Unauthorized 에러
빌드가 성공했음에도, Postman 테스트 시, 이렇게 에러가 나는 것은
spring security가 MVC 로직보다 먼저 인증/허가에 대한 권한을 검사하기 때문이다.> 방법 1 : build.gradle 의존성 부분에 Security 부분에 주석을 달아서 무시 (비권장)
> 방법 2 : security 인증/허가 관련 예외처리가 필요할 듯 하다.5. 404 Not Found 에러
@RestController@RequestMapping("/api/auth")@PostMapping("/register")RestfulAPI 처리하는 부분에 경로가 설정되어 있을 것이다.
요청할 때, /api/auth/register 경로로 요청했는지 확인해보자.
6. 400 Bad Request 에러
요청한 값의 타입과 WAS에서 정의한 타입이 다를 때나,
Json 포맷 형식이 약간이라도 상이하면 해당 에러가 출력된다.그래서 직접 Postman -> Body -> Json 형식을 써주니 200OK가 떨어짐.
'IT 공부방 [기본지식 정리] > Spring JPA' 카테고리의 다른 글
001. JPA란? (1) 2025.04.14 002. Spring 기본구조 (0) 2025.04.14 000. Spring JPA - MVC 패턴 설계 (1) 2025.04.09