From cc02ccac0150c55052fe4f29e57a879226019c11 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 18:22:59 +0000 Subject: [PATCH 1/2] Fix production DB driver issue and root path 500 error - Removed hardcoded `driver-class-name` from `application.yaml` to enable Spring Boot's driver auto-detection, fixing the startup failure in production where H2 driver was being used with a PostgreSQL URL. - Updated `ApiExceptionHandler` to handle `NoResourceFoundException`, ensuring that unmapped paths (like `/`) return a 404 Not Found response instead of a 500 Internal Server Error. - Added `NotFoundControllerTest` to verify the fix. Co-authored-by: devitq <118541411+devitq@users.noreply.github.com> --- .../adapters/web/ApiExceptionHandler.kt | 9 ++--- src/main/resources/application.yaml | 1 - .../controllers/NotFoundControllerTest.kt | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/test/kotlin/com/project/movienight/controllers/NotFoundControllerTest.kt diff --git a/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt b/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt index 29131e3..47e232c 100644 --- a/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt +++ b/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt @@ -11,20 +11,21 @@ import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestControllerAdvice +import org.springframework.web.servlet.resource.NoResourceFoundException import org.springframework.web.server.ResponseStatusException @RestControllerAdvice class ApiExceptionHandler { private val log = LoggerFactory.getLogger(javaClass) - @ExceptionHandler(EntityNotFoundException::class) + @ExceptionHandler(EntityNotFoundException::class, NoResourceFoundException::class) @ResponseStatus(HttpStatus.NOT_FOUND) - fun handleNotFound(exception: EntityNotFoundException): ErrorResponse { + fun handleNotFound(exception: Exception): ErrorResponse { val traceId = currentTraceId() - log.warn("Entity not found: traceId='{}', message='{}'", traceId, exception.message) + log.warn("Resource not found: traceId='{}', message='{}'", traceId, exception.message) return ErrorResponse( - message = exception.message ?: "Entity not found", + message = exception.message ?: "Resource not found", traceId = traceId, ) } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index c4248b1..a3b844c 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -7,7 +7,6 @@ spring: url: ${SPRING_DATASOURCE_URL:jdbc:h2:mem:movienight;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE} username: ${SPRING_DATASOURCE_USERNAME:sa} password: ${SPRING_DATASOURCE_PASSWORD:} - driver-class-name: ${SPRING_DATASOURCE_DRIVER_CLASS_NAME:org.h2.Driver} hikari: maximum-pool-size: ${SPRING_DATASOURCE_HIKARI_MAXIMUM_POOL_SIZE:20} minimum-idle: ${SPRING_DATASOURCE_HIKARI_MINIMUM_IDLE:5} diff --git a/src/test/kotlin/com/project/movienight/controllers/NotFoundControllerTest.kt b/src/test/kotlin/com/project/movienight/controllers/NotFoundControllerTest.kt new file mode 100644 index 0000000..8d0d6ff --- /dev/null +++ b/src/test/kotlin/com/project/movienight/controllers/NotFoundControllerTest.kt @@ -0,0 +1,35 @@ +package com.project.movienight.controllers + +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status + +@SpringBootTest +@AutoConfigureMockMvc(addFilters = false) +class NotFoundControllerTest { + @Autowired + private lateinit var mockMvc: MockMvc + + @Test + fun `requesting non-existent path should return 404 JSON response`() { + mockMvc + .perform(get("/non-existent-path")) + .andExpect(status().isNotFound) + .andExpect(jsonPath("$.message").exists()) + .andExpect(jsonPath("$.traceId").exists()) + } + + @Test + fun `requesting root path should return 404 JSON response`() { + mockMvc + .perform(get("/")) + .andExpect(status().isNotFound) + .andExpect(jsonPath("$.message").exists()) + .andExpect(jsonPath("$.traceId").exists()) + } +} -- 2.54.0 From 09393a1bd0f2f6d6948bac1c7444da22d59241ce Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 18:27:33 +0000 Subject: [PATCH 2/2] Fix DB driver auto-detection, root 404, and linting - Removed hardcoded `driver-class-name` from `application.yaml` to fix production startup failure with PostgreSQL. - Handled `NoResourceFoundException` in `ApiExceptionHandler` to return 404 for unmapped paths (like `/`). - Fixed import ordering in `ApiExceptionHandler.kt` to satisfy `ktlint`. - Added `NotFoundControllerTest` to verify fix. Co-authored-by: devitq <118541411+devitq@users.noreply.github.com> --- .../com/project/movienight/adapters/web/ApiExceptionHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt b/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt index 47e232c..0d9a087 100644 --- a/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt +++ b/src/main/kotlin/com/project/movienight/adapters/web/ApiExceptionHandler.kt @@ -11,8 +11,8 @@ import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestControllerAdvice -import org.springframework.web.servlet.resource.NoResourceFoundException import org.springframework.web.server.ResponseStatusException +import org.springframework.web.servlet.resource.NoResourceFoundException @RestControllerAdvice class ApiExceptionHandler { -- 2.54.0