해당 라이브러리는 Sangchu
프로젝트에서 사용하는 기본적인 기능들을 제공합니다.
build.gradle
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.CoffeeDrivenDevelopment:sangchu-common:0.0.3'
}
build.gradle.kts
repositories {
mavenCentral()
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.CoffeeDrivenDevelopment:sangchu-common:0.0.3")
}
공통으로 사용하는 에러 처리용 RestControllerAdvice
입니다.
SangchuConfig.java
@Configuration
public class SangchuConfig {
@Bean
public SangchuAdvice sangchuAdvice() {
return new SangchuAdvice();
}
}
SangchuConfig.kt
@Configuration
class SangchuConfig {
@Bean
fun sangchuAdvice(): SangchuAdvice {
return SangchuAdvice()
}
}
반복되는 ResponseEntity<MessageBody<Void>>
와 같은 클래스를 생성해주는 유틸입니다.
예시는 아래와 같습니다.
ResponseEntityFactory.java
@GetMapping("/v1")
public ResponseEntity<MessageBody<String>> get() {
ResponseEntity<MessageBody<Passport>> response = ResponseEntityFactory.ok("Hello", "world!");
return response;
}
ResponseEntityFactory.kt
@GetMapping("/v1")
fun get(): ResponseEntity<MessageBody<String>> {
val response: ResponseEntity<MessageBody<Passport>> = ResponseEntityFactory.ok(
message = "Hello",
body = "world!"
)
return response
}
이 외에도 헤더를 추가하여 전송할 수 있는 ResponseEntityFactoryWithHeaders
와 예외 처리를 담당하는 ResponseEntityExceptionFactory
가 있습니다.
해당 프로젝트에서 사용하는 라이브러리의 모음입니다.
2.15.3
을 사용하는 이유는 현재(2024.03.13) Spring Boot에서 사용하는 버전이 2.15.3이기 때문입니다.