자바 ORM 표준 JPA 프로그래밍이라는 책으로 공부를 하고 있는데 이 책에서는 h2 db에 maven을 사용하지만 나는 my sql과 gradle을 사용하려고 한다.
일단, 추후에 다른 프로젝트를 진행할 때 my sql로 진행할 확률이 높을 것 같아서 이 기회에 이걸로 익숙해지는 것이 좋을 것 같다는 생각이 들었고, 예전에 프로젝트 할 때도 my sql로 했어서 익숙하다.
또한, gradle을 사용하는 이유도 역시 익숙함이 크고.. 약간 구글링을 해보니 gradle이 더 최신이라고 해서 나쁘지 않다고 생각했다.
1. 인텔리제이에서 스프링 이니셜라이즈를 이용해 기본 세팅을 한다
1) 자바, gradle, jar 선택
2) 의존성에서는 spring data jpa, lombok, mysql driver, web 일단 4개만 설치
build 하다가 에러 발생
A problem occurred configuring root project 'jpa_study_01'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.2.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.2
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.2 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.2 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.2 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
이유
스프링부트 3.x.x 버전은 자바 17,
스프링부트 2.x.x 버전은 자바 11을 사용해야 함
근데 나는 자바 11이면서 스프링부트 3.x.x 사용해서 발생했던 문제
해결
build.gradle 들어가서
id 'org.springframework.boot' version '2.7.6'
이 부분을 수정함.
2. my sql에서 사용할 커넥션과 스키마를 생성
3. application.properties에 들어가서 jpa, my sql, 서버 설정을 한다
## server
server.address=localhost
server.port=8080
## jpa
spring.jpa.show-sql=true
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.generate-ddl=true
## my sql
spring.datasource.url=jdbc:mysql://localhost:3306/jpa_study?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul
spring.datasource.username=root
spring.datasource.password=본인패스워드입력
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
4. 인텔리제이 오른쪽 사이드에 있는 Database-+-Data source-my sql - general-user, password, database칸에 스키마 이름 입력
'Spring > jpa' 카테고리의 다른 글
[JPA] 영속성 관리 (0) | 2023.02.09 |
---|---|
[JPA] 엔티티 매니저 팩토리, 엔티티 매니저, 트랜잭션 (0) | 2023.02.09 |
[JPA] persistence.xml (0) | 2023.02.09 |
[JPA] 엔티티 설계 어노테이션 (0) | 2023.02.08 |
[JPA] 왜 JPA를 사용해야 하나? (0) | 2023.02.07 |