티스토리 뷰

코프링으로 개발 시 마주친 에러 관련 포스팅입니다.

개발 환경은 다음과 같습니다.

  • Spring Boot Version : 3.0.1
  • Java Version : 17

 

https://github.com/laboratory-kkoon9/kotlin-spring

배경

커피 주문 어플리케이션 내 스웨거를 도입하면서 발생한 에러입니다.

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    val kotlinVersion = "1.8.21"
    id("org.springframework.boot") version "3.0.1"
    id("io.spring.dependency-management") version "1.1.0"
    kotlin("jvm") version kotlinVersion
    kotlin("plugin.spring") version kotlinVersion
    kotlin("plugin.jpa") version kotlinVersion
    kotlin("kapt") version kotlinVersion

}

object DependencyVersions {
    const val SPRINGDOC_VERSION = "1.6.14"
}

group = "com.laboratory-kkoon9"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
}

dependencies {
    // webflux
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")

    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")

    // swagger
    implementation("org.springdoc:springdoc-openapi-webflux-core:${DependencyVersions.SPRINGDOC_VERSION}")
    implementation("org.springdoc:springdoc-openapi-webflux-ui:${DependencyVersions.SPRINGDOC_VERSION}")
    implementation("org.springdoc:springdoc-openapi-kotlin:${DependencyVersions.SPRINGDOC_VERSION}")

}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

다음과 같은 springdoc 라이브러리를 build.gradle.kts에 적어주었습니다.

  • springdoc-openapi-webflux-core:1.6.14
  • springdoc-openapi-webflux-ui:1.6.14
  • springdoc-openapi-starter-kotlin:1.6.14

다음은 SpringDocConfig 코드입니다.

package com.laboratorykkoon9.kotlinspring.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.info.Info
import org.slf4j.LoggerFactory
import org.springdoc.core.SpringDocUtils
import org.springframework.context.annotation.Profile
import org.springframework.web.server.WebSession

@Configuration
@Profile("local", "dev")
class SpringDocConfig() {

    private val logger = LoggerFactory.getLogger(SpringDocConfig::class.java)

    init {
        SpringDocUtils.getConfig().addRequestWrapperToIgnore(
            WebSession::class.java,
        )
    }

    @Bean
    fun openApi(): OpenAPI {
        logger.debug("Starting Swagger")

        return OpenAPI()
            .info(
                Info()
                    .title("cafe rest api")
                    .version("v0.0.1")
                    .description("Cafe REST API")
            )
    }
}

간단한 springdocs 구성만 잡아주었습니다.

그 뒤 swagger-ui 페이지를 들어가봤는데 404 에러가 발생했습니다.

해결

spring boot 3부터 springdoc 구성하는게 바뀌었습니다.

https://springdoc.org/v1/

요약하자면 위에 언급한 라이브러리는 제거해주시고 라이브러리를 교체해줘야 합니다.

implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.0.4")

그 다음, SpringDocConfig 내에 SpringDocUtils의 경로만 바꿔주시면 됩니다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함