2

I'm trying to migrate a Spring Boot project from Kotlin 1.2.71 to 1.3.0. When I update the Kotlin version, the application context fails to load with the following stack trace:

[...] Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'universityController' method public final com.vindedu.api.view.university.UniversityApplicationOverview com.vindedu.api.controller.UniversityController.getApplications(org.springframework.security.core.userdetails.UserDetails,boolean) to {[/uni/applications],methods=[GET]}: There is already 'universityController' bean method public static com.vindedu.api.view.university.UniversityApplicationOverview com.vindedu.api.controller.UniversityController.getApplications$default(com.vindedu.api.controller.UniversityController,org.springframework.security.core.userdetails.UserDetails,boolean,int,java.lang.Object) mapped. at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:576) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:540) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:264) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:250) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:127) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ... 98 more 

The following functions in my UniversityController class map to /uni/applications/...:

 @ApiOperation("Get applications received from students", tags = ["University API"], authorizations = [Authorization(value = "basicAuth")]) @RequestMapping(method = [RequestMethod.GET], path = ["/uni/applications"]) fun getApplications(@AuthenticationPrincipal user: UserDetails, @RequestParam("visible") visible: Boolean = true): UniversityApplicationOverview { return universityMessagingService.getApplications(user, visible) } @ApiOperation("Toggle application visibility for university", tags = ["University API"], authorizations = [Authorization(value = "basicAuth")]) @RequestMapping(method = [RequestMethod.PUT], path = ["/uni/applications/{id}/visible"]) fun toggleApplicationVisibility(@AuthenticationPrincipal user: UserDetails, @PathVariable id: Long): UniversityApplicationDetails { return universityMessagingService.toggleApplicationVisibility(user, id) } @ApiOperation("Get application received from student", tags = ["University API"], authorizations = [Authorization(value = "basicAuth")]) @RequestMapping(method = [RequestMethod.GET], path = ["/uni/applications/{id}"]) fun getApplication(@AuthenticationPrincipal user: UserDetails, @PathVariable id: Long): UniversityApplicationDetails { return universityMessagingService.getApplication(user, id) } @ApiOperation("Update application status", tags = ["University API"], authorizations = [Authorization(value = "basicAuth")]) @RequestMapping(method = [RequestMethod.PUT], path = ["/uni/applications/{id}/status"]) fun updateApplicationStatus(@AuthenticationPrincipal user: UserDetails, @PathVariable id: Long, @Valid @RequestBody updatedStatus: ApplicationStatusUpdate): UniversityApplicationDetails { return universityMessagingService.updateApplicationStatus(user, id, updatedStatus) } 

When I deleted my mappings listed above, I saw the same stack trace at runtime for another controller.

This project runs flawless with Kotlin 1.2.71. I appreciate any suggestions very much to make it work with Kotlin 1.3.0! My full build.gradle is listed below.

Please note:

  1. I compile and run this project with the following JDK:

    java version "11" 2018-09-25 Java(TM) SE Runtime Environment 18.9 (build 11+28) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode) 
  2. I can't update Spring Boot yet, due to classes in the project that depend on Spring Boot 1.x.

build.gradle:

buildscript { ext.kotlin_version = '1.3.0' // Was '1.2.71' ext.spring_boot_version = '1.5.4.RELEASE' repositories { jcenter() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version" classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version" } } apply plugin: 'idea' apply plugin: 'kotlin' apply plugin: 'kotlin-allopen' apply plugin: 'kotlin-noarg' apply plugin: 'org.springframework.boot' apply plugin: 'application' allOpen { annotation("org.springframework.boot.autoconfigure.SpringBootApplication") annotation("org.springframework.stereotype.Service") annotation("org.springframework.context.annotation.Configuration") } noArg { annotation("javax.persistence.Entity") } jar { baseName = 'vindedu-api' version = '0.0.1' } repositories { jcenter() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Required for Kotlin integration compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" // Required for Kotlin integration compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2' compile 'org.springframework.boot:spring-boot-starter-security' compile 'org.springframework.boot:spring-boot-starter-web' compile 'org.springframework.boot:spring-boot-starter-data-jpa' compile 'org.springframework.boot:spring-boot-starter-actuator' compile 'org.springframework.session:spring-session:1.3.1.RELEASE' compile 'io.springfox:springfox-swagger2:2.7.0' compile 'io.springfox:springfox-swagger-ui:2.7.0' compile 'org.postgresql:postgresql:42.1.4' compile 'org.flywaydb:flyway-core:4.2.0' // JAXB dependencies don't ship with the JDK anymore compile 'javax.xml.bind:jaxb-api:2.3.1' compile 'com.sun.xml.bind:jaxb-impl:2.3.1' compile 'javax.activation:activation:1.1.1' testCompile 'org.springframework.boot:spring-boot-starter-test' testCompile 'com.h2database:h2:1.4.196' } task wrapper(type: Wrapper) { gradleVersion = '4.10.2' } springBoot { mainClass = 'com.vindedu.api.ApplicationKt' } bootRun { systemProperty("PROP_NAME", "prop-value") } test { maxParallelForks = Runtime.runtime.availableProcessors() / 3 } 
2
  • Can you try adding name= to @RequestMapping ? Commented Nov 6, 2018 at 18:03
  • @HaseebR7 Thanks for your suggestion. Tried that, but it didn't make a difference. Commented Nov 8, 2018 at 13:27

1 Answer 1

4

From 1.3.0 Kotlin compiler doesn't generate bridge flag for default methods and new bytecode are only supported in newer Spring Boot versions. Please upgrade to Spring Boot 2. Reference issue: https://youtrack.jetbrains.com/issue/KT-27947

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for pointing me to that issue. I need to upgrade to Spring Boot 2, no way around it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.