λ°˜μ‘ν˜•

Framework/Springboot 12

[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..

[Springboot] Http Status 415 error 였λ₯˜ (415 Unsupported Media Type)

Intro μ•ˆλ…•ν•˜μ„Έμš”. Springboot λ₯Ό μ‚¬μš©ν•˜λ˜ 도쀑 Http Status 415 error μ—λŸ¬κ°€ λ°œμƒν•˜μ˜€μŠ΅λ‹ˆλ‹€. 415 Unsupported Media Type Why? κΈ°μ‘΄ μ»¨νŠΈλ‘€λŸ¬μ—μ„œ λ§€κ°œλ³€μˆ˜λ₯Ό λ°›κΈ° μœ„ν•΄ @RequestParam μ–΄λ…Έν…Œμ΄μ…˜μ„ μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€. λ§€κ°œλ³€μˆ˜ 5개λ₯Ό λ°›κ³  있던 터라 μƒλ‹Ήνžˆ λ³΅μž‘ν•΄ 보여 ν•΄λ‹Ή λ§€κ°œλ³€μˆ˜λ“€μ„ ν•˜λ‚˜μ˜ Dto Req 객체둜 λ°”κΏ”μ£Όμ—ˆμŠ΅λ‹ˆλ‹€. 이후 μ½”λ“œ 싀행을 ν–ˆλŠ”λ°, λ‹€μŒκ³Ό 같은 μ—λŸ¬κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. Springboot λ₯Ό 잘 λͺ°λΌμ„œ, ν•΄λ§Έμ§€λ§Œ 저희에겐 κ΅¬κΈ€λ‹˜μ΄ μžˆμŠ΅λ‹ˆλ‹€. 🀧 !! ꡬ글링 ν›„, μ œκ°€ μ‚¬μš©ν•œ μ–΄λ…Έν…Œμ΄μ…˜μ΄ 잘λͺ» λ˜μ—ˆλ‹€λŠ” 것을 μ•Œκ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€. @RequestParam λŠ” 단일 데이터λ₯Ό λ°›κΈ° μœ„ν•΄μ„œ μ‚¬μš©ν•˜κΈ° λ•Œλ¬Έμ—, λ‹€μŒκ³Ό 같이 μ—¬λŸ¬ λ§€κ°œλ³€μˆ˜κ°€ λ“€μ–΄..

λ°˜μ‘ν˜•