Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 알고리즘 입력받는 값
- 깃허브 프로필
- 신규 프로젝트 생성후 빌드시 오류
- Sanner와 BufferedReader의 차이점
- 파이썬 설치
- 파이썬 pip
- Visual Studio Code 파이썬
- 깃허브
- Redisson
- 깃허브 방문자
- 레디스
- visual studio code
- maven 오류
- spring-boot-starter-parent
- 프라이탁 파이썬
- 깃허브 뱃지
- 프라이탁
- pip업그레이드
- 윈도우10에 파이썬 설치
- 깃허브 리드미
- 깃허브 리드미 꾸미기
- 동등성
- setting.xml
- GitHub profile
- hashcode
- 파이썬 설치하기
- 분산락
- 프라이탁 알림봇
- 리드미 꾸미기
- Redis
Archives
- Today
- Total
yeo72.devlog
springboot 3.0 이상 버전에서 qeurydsl 사용하기 본문
querydsl 을 프로젝트에 적용하려고 이전 프로젝트 설정을 참조하여 셋팅
buildscript {
dependencies {
classpath("gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.10")
}
ext {
querydslVersion = "5.0.0"
querydslDir = "$buildDir/generated/querydsl"
}
}
plugins {
...
id "com.ewerk.gradle.plugins.querydsl" version '1.0.10'
...
}
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
querydsl.extendsFrom compileClasspath
}
dependencies {
...
implementation "com.querydsl:querydsl-jpa:${querydslVersion}"
implementation "com.querydsl:querydsl-apt:${querydslVersion}"
...
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
위와 같이 querydsl 관련 라이브러리 build.gradle 에 추가하고 build 하니 QuerydslConfig 파일에서 EntityManager를 찾지못하는 오류가 발생
import com.querydsl.jpa.impl.JPAQueryFactory;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@RequiredArgsConstructor
public class QuerydslConfig {
@PersistenceContext
private EntityManager entityManager;
@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
springboot 3.0 이상의 버전으로 가면서 javax에서 jakarta로 라이브러리가 변경되었다. 따라서 javax가 아닌 jakarta를 사용해 주어야하는데, 구글에 있는대로 build.gradle에 설정을 해 줬지만 계속
Unable to load class 'javax.persistence.Entity'. 에러가 떴다
…
캐시 문제인가 싶어서 gradle 캐시를 리셋하기도 했지만 계속 동일한 에러가 발생
하루종일 구글링 결과 구세주 발견
https://www.inflearn.com/chats/872346/spring-boot-3-querydsl-설정-공유-드립니다-mongodb
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
}
configurations {
querydsl.extendsFrom compileClasspath
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
}
dependencies {
// Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// Lombok
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Database
runtimeOnly 'org.postgresql:postgresql'
// queryDSL 설정
implementation "com.querydsl:querydsl-jpa:5.0.0:jakarta"
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
implementation "com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0"
// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.3'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'
// Test
testImplementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
sourceSets {
main {
java {
srcDirs = ["$projectDir/src/main/java", "$projectDir/build/generated"]
}
}
}
변경된 코드
clean 후 build하니 성공이고, Q 클래스도 잘 만들어지는 것을 확인했다.
인텔리제이의 오른쪽 gradle 설정에 들어가면 기존에는 complieQuerydsl이 존재했는데, 지금은 존재하지 않는다.
그렇지만 그냥 build 또는 compileJava 하면 Q클래스가 만들어진다.
아마 이전에 설정했던 플러그인에서 javax 관련 설정을 계속 받아와서 오류가 생긴 것 같다.(아닐수도)
'Study > Java' 카테고리의 다른 글
enum class mapping Error (1) | 2024.12.10 |
---|---|
[JAVA] ArrayList는 크기가 어떻게 변할까? (0) | 2023.11.24 |
[JAVA] StringBuilder와 StringBuffer 비교 (1) | 2023.11.22 |
[JAVA] 반복문 안에서 컬렉션 요소 변경하기 (0) | 2023.11.15 |
[Java] 동일성과 동등성 (0) | 2023.11.12 |