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

Native compile error when using Kotlin and WebFlux with coRouter #29658

Closed
Kotlin-GDE opened this issue Dec 7, 2022 · 6 comments
Closed

Native compile error when using Kotlin and WebFlux with coRouter #29658

Kotlin-GDE opened this issue Dec 7, 2022 · 6 comments
Labels
status: duplicate A duplicate of another issue theme: kotlin An issue related to Kotlin support

Comments

@Kotlin-GDE
Copy link

spring framework 6.0.2 (spring boot 3.0.0) , graalvm 22.3.0 (java 17.0.5)

routes dsl definition

fun routes(employeeHandler: EmployeeHandler, attendanceHandler: AttendanceHandler) = coRouter {

    "$APPLICATION_BASE_URL/employee".nest {
        GET("", employeeHandler::findAll)
        GET("/{id}", employeeHandler::find)
        POST("/save", employeeHandler::save)

        "/delete".nest {
            DELETE("", employeeHandler::deleteAll)
            DELETE("/{id}", employeeHandler::delete)
        }
    }


    "$APPLICATION_BASE_URL/login".nest {
        GET("", attendanceHandler::findAll)
        GET("/{deviceId}", attendanceHandler::findByEmployee)
        POST("/save", attendanceHandler::save)

        "/delete".nest {
            DELETE("", attendanceHandler::deleteAll)
            DELETE("/query", attendanceHandler::deleteByMonthAndYear)
            DELETE("/{deviceId}", attendanceHandler::deleteByEmployee)
        }
    }
}

spring main application

@SpringBootApplication
class AttendanceMainApp

fun main() {
    runApplication<AttendanceMainApp> {
        addInitializers(
            beans {
                bean<EmployeeService>()
                bean<EmployeeHandler>()
                bean<AttendanceService>()
                bean<AttendanceHandler>()
                bean(::routes)
            }
        )
    }
}

when launch gradle task: gradle nativeCompile an exception appear

2022-12-07T10:18:49.792+01:00  INFO 166674 --- [           main] dev.attendance.AttendanceMainAppKt       : Starting AttendanceMainAppKt using Java 17.0.5 with PID 166674 (/home/halim/Desktop/attendance-service/build/classes/kotlin/main started by halim in /home/halim/Desktop/attendance-service)
2022-12-07T10:18:49.796+01:00  INFO 166674 --- [           main] dev.attendance.AttendanceMainAppKt       : No active profile set, falling back to 1 default profile: "default"
2022-12-07T10:18:50.548+01:00  INFO 166674 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
2022-12-07T10:18:50.580+01:00  INFO 166674 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 25 ms. Found 0 Reactive MongoDB repository interfaces.
Exception in thread "main" java.lang.IllegalStateException: No constructor or factory method candidate found for Root bean: class [org.springframework.web.reactive.function.server.RouterFunction]; scope=singleton; abstract=false; lazyInit=true; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null and argument types []
        at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorOrFactoryMethod(ConstructorResolver.java:939)
        at org.springframework.beans.factory.support.RegisteredBean.resolveConstructorOrFactoryMethod(RegisteredBean.java:197)
        at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.<init>(BeanDefinitionMethodGenerator.java:79)
        at org.springframework.beans.factory.aot.BeanDefinitionMethodGeneratorFactory.getBeanDefinitionMethodGenerator(BeanDefinitionMethodGeneratorFactory.java:102)
        at org.springframework.beans.factory.aot.BeanDefinitionMethodGeneratorFactory.getBeanDefinitionMethodGenerator(BeanDefinitionMethodGeneratorFactory.java:118)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotProcessor.processAheadOfTime(BeanRegistrationsAotProcessor.java:45)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotProcessor.processAheadOfTime(BeanRegistrationsAotProcessor.java:35)
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.getContributions(BeanFactoryInitializationAotContributions.java:67)
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.<init>(BeanFactoryInitializationAotContributions.java:49)
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.<init>(BeanFactoryInitializationAotContributions.java:44)
        at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
        at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
        at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
        at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
        at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
        at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:76)

whats wrong !!!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 7, 2022
@bclozel
Copy link
Member

bclozel commented Dec 7, 2022

Could you share a minimal sample application that reproduces the problem? Ideally, an application created from start.spring.io and shared as a git repository or a zip file. Thanks!

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Dec 7, 2022
@Kotlin-GDE
Copy link
Author

this is the link of ATENDANCE-SERVICE

https://github.com/halimpuckjava/attendance-service.git

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 7, 2022
@scottfrederick
Copy link
Contributor

This sample can be simplified significantly and still reproduce the problem.

  1. Create a new project from start.spring.io using these options: https://start.spring.io/#!type=gradle-project-kotlin&language=kotlin&platformVersion=3.0.0&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=native,webflux

  2. Add src/main/kotlin/com/example/demo/Routes.kt that looks like this:

package com.example.demo

import org.springframework.web.reactive.function.server.coRouter

fun routes() = coRouter {
}
  1. Modify main in DemoApplication.kt to look like this:
fun main(args: Array<String>) {
	runApplication<DemoApplication> {
		addInitializers(
			beans {
				bean(::routes)
			}
		)
	}
}

Running ./gradlew nativeCompile give the same error as above.

@scottfrederick scottfrederick changed the title Sprign native issue Native compile error when using Kotlin and WebFlux with coRouter Dec 7, 2022
@scottfrederick
Copy link
Contributor

@halimpuckjava As a work-around, this change to main in your sample allows ./gradle nativeCompile to succeed:

fun main() {
    runApplication<AttendanceMainApp> {
        addInitializers(
            beans {
                bean<EmployeeService>()
                bean<EmployeeHandler>()
                bean<AttendanceService>()
                bean<AttendanceHandler>()
            }
        )
    }
}

@Configuration
class RouterConfiguration {

    @Bean
    fun router() = ::routes

}

@bclozel bclozel transferred this issue from spring-projects/spring-boot Dec 7, 2022
@poutsma poutsma added the theme: kotlin An issue related to Kotlin support label Dec 8, 2022
@Kotlin-GDE
Copy link
Author

thanks, i will try it and give you a feed back

@sdeleuze sdeleuze added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Jan 9, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 9, 2023

This issue is a duplicate of #29555.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue theme: kotlin An issue related to Kotlin support
Projects
None yet
Development

No branches or pull requests

6 participants