λ°˜μ‘ν˜•

Framework/Springboot 13

[Springboot] JPA와 pageable ν™œμš©ν•œ sort μ •λ ¬ κ΅¬ν˜„ 방법

Introμ•ˆλ…•ν•˜μ„Έμš”. 이번 μ‹œκ°„μ—λŠ” spring boot μ—μ„œ JPA와 pageable ν™œμš©ν•œ sort μ •λ ¬ κ΅¬ν˜„ 방법에 λŒ€ν•΄ μ•Œμ•„λ³΄λ„λ‘ ν•˜κ² μŠ΅λ‹ˆλ‹€. user 데이터가 μžˆλ‹€λŠ” κ°€μ •ν•˜μ— 진행해보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€.  1. User μ—”ν‹°ν‹° μ •μ˜ User μ—”ν‹°ν‹°μ—λŠ” id, name, email, createdDate λ“±μ˜ ν•„λ“œκ°€ μžˆλ‹€κ³  κ°€μ •ν•©λ‹ˆλ‹€.@Entitydata class User( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long, val name: String, val email: String, @CreatedDate val createdDate: LocalDateTime) 2. UserReposit..

[SpringBoot] Failed to instantiate Factory method 'someHotMongoFactory' threw exception with message: Cannot invoke "String.startsWith(String)" because "connectionString" is null

Intro mongodb μ—μ„œ μΆ”κ°€λœ μ»¬λ ‰μ…˜μ„ μŠ€ν”„λ§λΆ€νŠΈμ—μ„œ ν™œμš©ν•˜λ˜ 도쀑 μ•„λž˜μ˜ μ—λŸ¬κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. Failed to instantiate [org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory]: Factory method 'someHotMongoFactory' threw exception with message: Cannot invoke "String.startsWith(String)" because "connectionString" is null Why? 이 였λ₯˜λŠ” connectionString이 null이기 λ•Œλ¬Έμ— "String.startsWith(String)"λ₯Ό ν˜ΈμΆœν•  수 μ—†λ‹€λŠ” 것을 λ‚˜νƒ€λƒ…λ‹ˆλ‹€. SomeHotMo..

[SpringBoot] kotlin + SpringBoot + mongodb MongoRepositoryμ—μ„œ limit μ‚¬μš©ν•˜λŠ” 방법

Intro μ•ˆλ…•ν•˜μ„Έμš”. μ΄λ²ˆμ‹œκ°„μ—λŠ” μŠ€ν”„λ§λΆ€νŠΈ + mongodb MongoRepositoryμ—μ„œ limit μ‚¬μš©ν•˜λŠ” 방법에 λŒ€ν•΄ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€. How to solve the problem μ•„λž˜ μ½”λ“œμ™€ 같이 limit() λ©”μ„œλ“œλ₯Ό ν™œμš©ν•˜μ—¬ μ›ν•˜λŠ” count 만큼 μ‘°νšŒν•  수 μžˆμŠ΅λ‹ˆλ‹€. suspend fun getRecentData(createAt: Instant): List? { val query = Query() query.with( Sort.by(Sort.Direction.DESC, "createAt") ) query.limit(3) return metaHotMongoTemplate.find(query, SomeDTO::class.java, collectionName).collectList() .awa..

[SpringBoot] μŠ€ν”„λ§ JPA limit pagesize μ΅œλŒ€κ°’(maxSize) μ§€μ •ν•˜λŠ” 방법

Intro μ•ˆλ…•ν•˜μ„Έμš”. μ΄λ²ˆμ‹œκ°„μ—λŠ” μŠ€ν”„λ§ JPAμ—μ„œ pageSize νŽ˜μ΄μ§€ μ‚¬μ΄μ¦ˆλ₯Ό μ΅œλŒ€κ°’μœΌλ‘œ μ§€μ •ν•˜λŠ” 방법에 λŒ€ν•΄ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€. How to set to maxSize @PageableDefault μ–΄λ…Έν…Œμ΄μ…˜μ„ ν™œμš©ν•˜μ—¬, sizeλ₯Ό Integer.MAX_VALUE둜 μ„€μ •ν•˜λ©΄ λ©λ‹ˆλ‹€. sizeλ₯Ό 확인해보면, 2000으둜 μ„€μ •λœ 것을 λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€. public SomeResponseObject getSomething( @PageableDefault(size = Integer.MAX_VALUE) Pageable page ) { return someService.getSomething(page); } https://stackoverflow.com/questions/23751193/spring-data-..

[Springboot] νŽ˜μ΄μ§€λ„€μ΄μ…˜ Pageable 객체에 λŒ€ν•΄ μ•Œμ•„λ³΄μž

Intro μ•ˆλ…•ν•˜μ„Έμš”. 이번 μ‹œκ°„μ—λŠ” μŠ€ν”„λ§λΆ€νŠΈμ˜ Pageable νŽ˜μ΄μ§€λ„€μ΄μ…˜ 객체에 λŒ€ν•΄ μ•Œμ•„λ³΄λ„λ‘ ν•˜κ² μŠ΅λ‹ˆλ‹€. 제 경우 Taskλ₯Ό μ§„ν–‰ν•˜λ˜ 도쀑 νŽ˜μ΄μ§€λ„€μ΄μ…˜μ„ μΆ”κ°€ν•΄μ•Ό ν•˜λŠ” μš”κ΅¬μ‚¬ν•­μ΄ λ“€μ–΄μ˜ΈμŠ΅λ‹ˆλ‹€. νŽ˜μ΄μ§€λ„€μ΄μ…˜μ„ κ΅¬ν˜„ν•˜λŠ” 방법은 μ—¬λŸ¬κ°€μ§€κ°€ μžˆλŠ”λ°μš”, κ·Έμ€‘μ—μ„œλ„ μ €λŠ” Spring Data JPAλ₯Ό μ΄μš©ν–ˆμŠ΅λ‹ˆλ‹€. Spring Data JPAλ₯Ό μ΄μš©ν•˜λ©΄ Pageable 객체λ₯Ό μ‚¬μš©ν•˜μ—¬ νŽ˜μ΄μ§€λ„€μ΄μ…˜(pagination) 정보λ₯Ό μ‰½κ²Œ 관리할 수 있기 λ•Œλ¬Έμž…λ‹ˆλ‹€. JPA Query λ©”μ„œλ“œμ˜ νŒŒλΌλ―Έν„°λ‘œ Pageable을 λ„˜κ²¨μ„œ DB에 쿼리λ₯Ό 날릴 수 μžˆμŠ΅λ‹ˆλ‹€. 즉, μ•Œμ•„μ„œ 잘 ν•΄μ£ΌκΈ° λ•Œλ¬Έμ— 맀우 νŽΈν•˜κ²Œ μ‚¬μš©μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€ :-) Pageable PageableλŠ” Pagination μš”μ²­ 정보듀을 λ‹΄κΈ° μœ„ν•œ 좔상 인..

[Springboot] μŠ€ν”„λ§λΆ€νŠΈ + λͺ½κ³ (mongo)μ—μ„œ OR 쿼리 query μ‚¬μš©ν•˜λŠ” 방법 (+ Criteria)

Intro μ•ˆλ…•ν•˜μ„Έμš”. 이번 μ‹œκ°„μ—λŠ” μŠ€ν”„λ§λΆ€νŠΈ + λͺ½κ³ (mongo)μ—μ„œ OR 쿼리 query μ‚¬μš©ν•˜λŠ” 방법에 λŒ€ν•΄ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€. How to do Criteria APIλ₯Ό μ‚¬μš©ν•˜μ—¬ μ•„λž˜μ™€ 같이 μ‚¬μš©ν•˜λ©΄ λ©λ‹ˆλ‹€. Criteria criteria = new Criteria(); criteria.orOperator(Criteria.where("A").is(10),Criteria.where("B").is(20)); Query query = new Query(criteria); mongoOps.find(query, .class, "collectionName"); +) 참고둜 Criteria 은 κΈ°μ€€κ°’μ΄λΌλŠ” μ˜λ―Ένž™λ‹ˆλ‹€. find λ©”μ†Œλ“œ μ•ˆμ—μ„œ { age: { $gt: 18 } } 와 같은 쑰건문을 μž…λ ₯ν•˜λŠ” λΆ€λΆ„..

[Springboot] JPA Projection ν”„λ‘œμ μ…˜ ν•˜λŠ” 방법

Intro μ•ˆλ…•ν•˜μ„Έμš”. 이번 μ‹œκ°„μ—λŠ” Springboot μŠ€ν”„λ§λΆ€νŠΈ JPAμ—μ„œ ν”„λ‘œμ μ…˜ ν•˜λŠ” 방법에 λŒ€ν•΄ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€. Projection? λ¨Όμ € 듀어가기에 μ•žμ„œ κ°„λ‹¨ν•˜κ²Œ ν”„λ‘œμ μ…˜μ— λŒ€ν•œ 의미λ₯Ό μ‚΄νŽ΄λ³Όκ²Œμš”. ν”„λ‘œμ μ…˜μ€ μ—”ν‹°ν‹°μ˜ 속성이 λ§Žμ„ λ•Œ 일뢀 λ°μ΄ν„°λ§Œ κ°€μ Έμ˜€λŠ” 방법을 μ˜λ―Έν•©λ‹ˆλ‹€. 더 μžμ„Έν•œ λ‚΄μš©μ΄ κΆκΈˆν•˜μ‹œλ©΄ 일전에 μ œκ°€ 정리해놓은 ν¬μŠ€νŒ… μ°Έκ³  λ°”λžλ‹ˆλ‹€ :) [MongoDB] ν”„λ‘œμ μ…˜ (Projection) μ΄λž€? projection query μ‚¬μš©λ²• How to do μ•„λž˜μ˜ User domain 객체λ₯Ό μ°Έκ³ ν•˜μ—¬ μ„€λͺ…ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€. @Document(collection = "user") class User( val userId: String?, val userName: String?, val user..

[Springboot] Postman Rest API μš”μ²­ Getting not supported media type error / 415 Unsupported MediaType

Intro μ•ˆλ…•ν•˜μ„Έμš”. μŠ€ν”„λ§λΆ€νŠΈμ—μ„œ Api ν…ŒμŠ€νŠΈλ₯Ό ν•˜κΈ° μœ„ν•΄ postman 을 μ‚¬μš©ν•˜λ˜ 도쀑 λ‹€μŒμ˜ μ• λŸ¬κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. 415 Unsupported MediaType 참고둜, μ €λŠ” 컨트둀러 λ‹¨μ—μ„œ @PostMappingκ³Ό @RequestBody μ–΄λ…Έν…Œμ΄μ…˜μ„ μ‚¬μš©ν–ˆκ³ , Put μš”μ²­μœΌλ‘œ μ•„λž˜ λ‚΄μš©μ„ 전달해 μ—…λ°μ΄νŠΈλ₯Ό μ‹œμΌœμ€˜μ•Ό ν–ˆμŠ΅λ‹ˆλ‹€. { "isOwner": true, "isStaff": false, } Why? μ§€μ›ν•˜μ§€ μ•ŠλŠ” λ―Έλ””μ–΄ νƒ€μž…μ΄λΌλŠ” μ˜λ―Έμž…λ‹ˆλ‹€. μ†ŒμŠ€ μžμ²΄μ— λ¬Έμ œκ°€ μžˆλŠ” 쀄 μ•Œκ³ , μ—΄μ‹¬νžˆ ꡬ글링 ν–ˆμ§€λ§Œ λ¬Έμ œλŠ” λ”°λ‘œ μžˆμ—ˆμŠ΅λ‹ˆλ‹€. How to solve the problem 처음 ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•΄ Postman > Body νƒ­ > rawλ₯Ό 선택 ν›„ ν•΄λ‹Ή json νŒŒμΌμ„ λ„£μ–΄ μš”μ²­μ„ ν•΄μ€¬λŠ”λ°μš”, μ•Œκ³ ..

[Springboot] μŠ€ν”„λ§λΆ€νŠΈ+μ½”ν‹€λ¦° jar.enabled = true not working 였λ₯˜ λ°œμƒ

Intro μ•ˆλ…•ν•˜μ„Έμš”. Springboot + kotlin 개발 ν™˜κ²½μ—μ„œ gradle μ„€μ •μ˜ "jar.enabled = true" 이 λ™μž‘ν•˜μ§€ μ•ŠλŠ” 였λ₯˜κ°€ λ°œμƒν•˜μ˜€μŠ΅λ‹ˆλ‹€. 일반 Springboot + Java 개발 ν™˜κ²½μ—μ„œλŠ” λ‹€μŒμ˜ 섀정이 잘 μž‘λ™ν•˜λŠ”λ°, μ½”ν‹€λ¦°μ—μ„œλŠ” μž‘λ™ν•˜μ§€ μ•Šλ”λΌκ³ μš”. How to solve the problem ꡬ글링 ν›„, μ•„λž˜μ˜ μ½”λ“œλ₯Ό μ°Ύμ•„ μ μš©ν•΄λ΄€λ”λ‹ˆ μ •μƒμ μœΌλ‘œ μž‘λ™ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 이 외에도 μ—¬λŸ¬ 방법이 μžˆλŠ” 것 κ°™μœΌλ‹ˆ ν¬μŠ€νŒ… ν•˜λ‹¨ μ‚¬μ΄νŠΈλ₯Ό μ°Έκ³ ν•΄μ£Όμ‹œλ©΄ 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€. tasks.withType { archiveBaseName.set("octo-mobile-api") } https://github.com/spring-projects/spring-boot/issues/10238

[Springboot] gradlew command not found / IntelliJ μΈν…”λ¦¬μ œμ΄ gradlew λΉŒλ“œ 였λ₯˜

Intro μ•ˆλ…•ν•˜μ„Έμš”. μΈν…”λ¦¬μ œμ΄ ν„°λ―Έλ„μ—μ„œ gradlew λΉŒλ“œλ₯Ό ν•˜λ €λ˜ 도쀑 μ•„λž˜μ™€ 같은 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. Why? μ €λŠ” μ•„λž˜μ™€ 같은 λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•˜μ˜€λŠ”λ°μš”, ꡬ글링을 ν•˜λ‹€κ°€ μ²˜μŒμ—λŠ” κΆŒν•œ 문제인 쀄 μ•Œκ³  κΆŒν•œμ„ λ°”κΏ”λ΄€μŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ 계속 같은 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. κ·Έλž˜μ„œ 더 ꡬ글링을 ν•΄λ΄€κ³ , μ œκ°€ 바보같은 μ‹€μˆ˜λ₯Ό ν•˜κ³  μžˆμ—ˆμŒμ„ κΉ¨λ‹¬μ•˜μŠ΅λ‹ˆλ‹€. gradlew build How to solve the problem λ°”λ‘œ λͺ…λ Ήμ–΄ μ•žμ— ./ λ₯Ό 뢙여주지 μ•Šμ•˜κΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€. πŸ˜… λ¦¬λˆ…μŠ€/λ§₯κ³Ό μœˆλ„μš° λͺ…λ Ήμ–΄ μ‚¬μš©λ²•μ΄ λ‹€λ₯΄λ‹ˆ μ•„λž˜ λ‚΄μš© μ°Έκ³  λΆ€νƒλ“œλ¦½λ‹ˆλ‹€. Linux / MacOS ./gradlew Windows .\gradlew https://stackoverflow.com/questions/41700798/gr..

λ°˜μ‘ν˜•