Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple native Kotlin function app fails to start in Docker - Could not resolve matching constructor #675

Closed
frayneposset opened this issue Mar 22, 2021 · 6 comments

Comments

@frayneposset
Copy link

Describe the bug

Simple Kotlin function app fails to start in native docker image:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'toUpperCase_registration': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowire

Sample
Write a simple Spring Boot Kotlin application with a simple function exposed as a bean.

Build then run in docker:

./gradlew build bootBuildImage

docker run functionnative:0.0.1-SNAPSHOT

Kotlin code:

package com.example.functionnative

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean

@SpringBootApplication
class FunctioningApplication {
	@Bean
	fun toUpperCase(): (String) -> String = { it.toUpperCase() }
}


fun main(args: Array<String>) {
	runApplication<FunctioningApplication>(*args)
}




build.gradle.kts :

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage

plugins {

	id("org.springframework.boot") version "2.4.4"
	id("io.spring.dependency-management") version "1.0.11.RELEASE"
	kotlin("jvm") version "1.4.30"
	kotlin("plugin.spring") version "1.4.30"
	id("org.springframework.experimental.aot") version "0.9.1-SNAPSHOT"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
	maven { url = uri("https://repo.spring.io/snapshot") }
	mavenCentral()
}

extra["springCloudVersion"] = "2020.0.2"

dependencies {
	implementation("org.springframework.boot:spring-boot-starter")
	implementation("org.springframework.boot:spring-boot-starter-web")
	implementation("org.jetbrains.kotlin:kotlin-reflect")
	implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
	listOf("context","kotlin","web").forEach {
		implementation("org.springframework.cloud:spring-cloud-function-$it")
	}
	testImplementation("org.springframework.boot:spring-boot-starter-test")
}

dependencyManagement {
	imports {
		mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
	}
}

tasks.withType<KotlinCompile> {
	kotlinOptions {
		freeCompilerArgs = listOf("-Xjsr305=strict")
		jvmTarget = "11"
	}
}

tasks.withType<Test> {
	useJUnitPlatform()
}

tasks.withType<BootBuildImage> {
	builder = "paketobuildpacks/builder:tiny"
	environment = mapOf("BP_NATIVE_IMAGE" to "true")
}

@olegz
Copy link
Contributor

olegz commented Mar 22, 2021

Are you saying it only breaks in native docker image?

@frayneposset
Copy link
Author

frayneposset commented Mar 22, 2021

Yes, works ok normally, broken in native docker image.

@olegz
Copy link
Contributor

olegz commented Mar 23, 2021

@frayneposset I had a discussion with some of our guys on spring-native team and they advised to have this issue moved to https://github.com/spring-projects-experimental/spring-native/issues. Unfortunately we can't move issues across the orgs so I am going to close this and ask you to raise a new one in the provided link (you can still link to this issue form there)

Also, it would greatly speed up the resolution process if you can create a small repo in GitHub with a bare minimum to reproduce the issue, given that the actual problem could be anywhere (code, missing plugin etc) we need to have a view into your exact process.

@olegz olegz closed this as completed Mar 23, 2021
@olegz
Copy link
Contributor

olegz commented Mar 23, 2021

Also, i was just told that org.springframework.experimental.aot:0.9.1 has just been released, so give it a try as well.

Last but not least I have a hint of my own and suspect that there may be issues with the class in question given the error you see Could not resolve matching constructor. It's private which is generally OK with spring dependency injection mechanisms, but could potentially be an issue with native, so i'll let you know when the new snapshots will be available.

olegz added a commit that referenced this issue Mar 23, 2021
@olegz
Copy link
Contributor

olegz commented Mar 23, 2021

Just an FYI. The new spring-cloud-function snapshots with the updated class is available

@frayneposset
Copy link
Author

New issue raised with GIT repo example :

spring-attic/spring-native#652

olegz added a commit that referenced this issue Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants