Skip to content

Commit

Permalink
Merge pull request #93 from kazokmr/dev
Browse files Browse the repository at this point in the history
Spring Boot を 3.1に更新した
  • Loading branch information
kazokmr committed May 19, 2023
2 parents 012974b + 40f5fd8 commit f4aa7eb
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 34 deletions.
19 changes: 6 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import com.google.protobuf.gradle.id
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.8.20"
kotlin("plugin.spring") version "1.8.20"
id("org.springframework.boot") version "3.0.5"
kotlin("jvm") version "1.8.21"
kotlin("plugin.spring") version "1.8.21"
id("org.springframework.boot") version "3.1.0"
id("io.spring.dependency-management") version "1.1.0"
id("com.thinkimi.gradle.MybatisGenerator") version "2.4"
id("jacoco")
Expand Down Expand Up @@ -42,12 +42,6 @@ repositories {
mavenCentral()
}

dependencyManagement {
imports {
mavenBom("org.testcontainers:testcontainers-bom:1.17.6")
}
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
Expand All @@ -73,11 +67,10 @@ dependencies {
implementation("io.github.lognet:grpc-spring-boot-starter:5.0.0")
runtimeOnly("org.postgresql:postgresql")
runtimeOnly("io.micrometer:micrometer-registry-prometheus")
// runtimeOnly("io.micrometer:micrometer-tracing-bridge-otel")
// runtimeOnly("io.opentelemetry:opentelemetry-exporter-zipkin")
runtimeOnly("io.micrometer:micrometer-tracing-bridge-brave")
runtimeOnly("io.zipkin.reporter2:zipkin-reporter-brave")
runtimeOnly("io.micrometer:micrometer-tracing-bridge-otel")
runtimeOnly("io.opentelemetry:opentelemetry-exporter-zipkin")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
testImplementation("org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.1")
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.book.manager.config.IntegrationTestConfiguration
import com.book.manager.domain.model.Book
import com.book.manager.domain.model.BookWithRental
import com.book.manager.domain.model.Rental
import com.book.manager.infrastructure.database.testcontainers.TestContainerDataRegistry
import com.book.manager.presentation.form.AdminBookResponse
import com.book.manager.presentation.form.BookInfo
import com.book.manager.presentation.form.GetBookDetailResponse
Expand Down Expand Up @@ -40,7 +39,7 @@ import java.util.stream.Stream

@SpringBootTest(webEnvironment = RANDOM_PORT)
@Import(IntegrationTestConfiguration::class)
internal class BookManagerIntegrationTests : TestContainerDataRegistry() {
internal class BookManagerIntegrationTests {

@Autowired
private lateinit var exchangeFilter: CustomExchangeFilterFunction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.book.manager.config

import com.book.manager.infrastructure.database.testcontainers.TestContainerDataRegistry
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.boot.testcontainers.context.ImportTestcontainers
import org.springframework.context.annotation.Bean

@TestConfiguration
@ImportTestcontainers(TestContainerDataRegistry::class) // From Spring Boot 3.1 intTestはDBが常時必要なのでConfigurationでTestContainerを起動させる
class IntegrationTestConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.springframework.stereotype.Component
)
@Component
class MicrometerInterceptor(private val observationRegistry: ObservationRegistry) : Interceptor {
override fun intercept(invocation: Invocation): Any {
override fun intercept(invocation: Invocation): Any? {
val mappedStatement = invocation.args[0] as MappedStatement
return Observation.createNotStarted("mybatis.query", observationRegistry)
.lowCardinalityKeyValue("id", mappedStatement.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.book.manager.presentation.handler

import com.fasterxml.jackson.databind.exc.InvalidFormatException
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
import com.fasterxml.jackson.databind.exc.MismatchedInputException
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatusCode
import org.springframework.http.ResponseEntity
Expand Down Expand Up @@ -39,17 +39,17 @@ class BookManagerExceptionHandler : ResponseEntityExceptionHandler() {
request: WebRequest
): ResponseEntity<Any>? {
val body = when (val cause = ex.cause) {
is MissingKotlinParameterException -> {
cause.path.joinToString(",") { it.fieldName }
.let { mapOf(Pair("入力パラメータがありません", it)) }
}

is InvalidFormatException -> {
cause.path.joinToString(",") {
"type of ${it.fieldName} should be ${cause.targetType}. but value was ${cause.value}"
}.let { mapOf(Pair("入力パラメータの型が一致しません", it)) }
}

is MismatchedInputException -> {
cause.path.joinToString(",") { it.fieldName }
.let { mapOf(Pair("入力パラメータがありません", it)) }
}

else -> mapOf(Pair("予期せぬエラー ${cause?.javaClass?.name}", ex.localizedMessage))
}
return handleExceptionInternal(ex, body, headers, status, request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.book.manager.infrastructure.database.testcontainers

import org.springframework.boot.testcontainers.service.connection.ServiceConnection
import org.springframework.test.context.DynamicPropertyRegistry
import org.springframework.test.context.DynamicPropertySource
import org.testcontainers.containers.GenericContainer
Expand All @@ -13,8 +14,9 @@ abstract class TestContainerDataRegistry {

companion object {
@Container
@ServiceConnection
@JvmStatic
val database = PostgreSQLContainer<Nothing>(DockerImageName.parse("postgres:latest")).apply {
val database = PostgreSQLContainer<Nothing>(DockerImageName.parse("postgres").withTag("latest")).apply {
withDatabaseName("test")
withUsername("user")
withPassword("pass")
Expand All @@ -24,18 +26,17 @@ abstract class TestContainerDataRegistry {
}

@Container
@ServiceConnection
@JvmStatic
val redis: GenericContainer<*> = GenericContainer<Nothing>(DockerImageName.parse("redis:latest")).apply {
withExposedPorts(6379)
}
val redis: GenericContainer<*> =
GenericContainer<Nothing>(DockerImageName.parse("redis").withTag("latest")).apply {
withExposedPorts(6379)
}

@DynamicPropertySource
@JvmStatic
fun setUp(registry: DynamicPropertyRegistry) {
registry.add("spring.datasource.url", database::getJdbcUrl)
registry.add("spring.datasource.username", database::getUsername)
registry.add("spring.datasource.password", database::getPassword)
registry.add("spring.data.redis.host", redis::getHost)
// FIXME: RedisのportだけはDynamicPropertySourceで定義しないとアクセスしてくれない
registry.add("spring.data.redis.port", redis::getFirstMappedPort)
}
}
Expand Down

0 comments on commit f4aa7eb

Please sign in to comment.