使用 Kotlin 的 SpringBoot 云函数

问题描述

所以我希望让我的 REST API 在谷歌云函数上运行。

我从一个返回 UserDto 对象和保存 UserDto 对象的简单函数开始。

@Component
class UserFunctions: supplier<UserDto?>,Consumer<UserDto> {
    @Autowired
    lateinit var userService: UserService

    override fun get(): UserDto? {
        val context = SecurityContextHolder.getContext()
        return userService.getUserByEmail(context.authentication.name)
    }

    override fun accept(userDto: UserDto) {
        userService.saveUser(userDto,SecurityContextHolder.getContext().authentication.name)
    }
} 

但是每当我开始这个项目时,我都会得到

Could not invoke function: Could not construct an instance of org.springframework.cloud.function.adapter.gcp.GcfJarLauncher: java.lang.reflect.InvocationTargetException: Error creating bean with name 'userFunctions': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDeFinitionException: No qualifying bean of type 'ca.mynormative.api.userapi.data.services.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} -> [Help 1]
 

出于某种原因,它不会自动装配服务。经典的 REST 版本运行良好。我似乎无法弄清楚我错过了什么。有什么帮助吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)