Я пытаюсь перенести проект Spring Boot с Kotlin 1.2.71 на 1.3.0.
Когда я обновляю версию Kotlin, контекст приложения не загружается со следующей трассировкой стека:
[...]
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
Следующие функции в моем UniversityController
сопоставлении классов с /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)
}
Когда я удалил свои сопоставления, перечисленные выше, я увидел ту же трассировку стека во время выполнения для другого контроллера.
Этот проект работает безупречно с Kotlin 1.2.71. Я очень ценю любые предложения, чтобы заставить его работать с Kotlin 1.3.0! Мой полный build.gradle
указан ниже.
Обратите внимание:
Я компилирую и запускаю этот проект со следующим 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)
Я пока не могу обновить Spring Boot из-за классов в проекте, которые зависят от 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
}