Issue
I'm implementing a global Exception Handler with Spring Boot @ControllerAdivce in Kotlin with Gradle
class SensorTypeNotFoundException(message: String) : RuntimeException(message)
if I throw SensorTypeNotFoundException, I have 500 Internal Server Error
I can't understand why Spring Boot doesn't see my ExceptionController.
Can anyone help please?
This is my CustomExceptionController:
@ControllerAdvice
@RestController
class CustomExceptionController {
private val logger = LoggerFactory.getLogger(javaClass.name)
enum class ErrorKeys {
***
}
@ExceptionHandler(Exception::class)
fun handleException(exception: Exception): ResponseEntity<ExceptionResponse> {
***
}
private fun createExceptionResponseEntity(exception: Exception): ResponseEntity<ExceptionResponse> {
***
}
}
private fun buildResponse(message: String?, errorKey: ErrorKeys, httpStatus: HttpStatus): ResponseEntity<ExceptionResponse> {
***
)
return ResponseEntity(responseEntity, responseEntity.status)
}
}
build.gradle.kts:
...
plugins {
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
...
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}
...
Solution
Thanks for your help, I've solved the problem
The problem was, that in my Controller Class the return value was <List<Any>>
, but it should be ResponseEntity<List<Any>>
Answered By - JetBrains
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.