首页 > 解决方案 > 是什么导致“通过方法'setTargetDatastore'参数0表达的不满足的依赖关系”?

问题描述

我是 Spring 应用程序的新手,我正在尝试使用 Kotlin + Spring + GORM 集成一个项目(这需要使用 Groovy)。当我尝试运行它时,我得到:

上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“messageController”的bean时出错:通过方法“setTargetDatastore”参数0表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.BeanCreationException

我在项目中只有 5 个文件,包括 build.gradle。

消息.groovy

import grails.gorm.annotation.Entity
import groovy.transform.ToString
import org.grails.datastore.gorm.GormEntity

@ToString
@Entity
class Message implements GormEntity<Message> {
    String user;
    String date;
    String message;
}

消息服务

import domain.Message
import groovy.transform.CompileStatic
import org.springframework.stereotype.Service

@CompileStatic
@grails.gorm.services.Service(Message)
@Service
interface MessageService {
    List<Message> findAll()
}

消息控制器.groovy

@RestController
@Transactional
class MessageController {

    @Autowired
    MessageService messageService

    @RequestMapping("/")
    List<String> index() {
        return messageService.findAll().collect { "[" + it.user + "@" + it.date + ": " + it.message + "]" }
    }

    @RequestMapping(value = "/save/", method = RequestMethod.POST)
    String save(@RequestBody Message message) {
        message.save()
        return "Saved"
    }
}

应用程序.kt

@SpringBootApplication
class SimManagerApplication

fun main(args: Array<String>) {

    SpringApplication.run(SimManagerApplication::class.java, *args)
}

build.gradle 依赖项

dependencies {
    compile('org.springframework.boot:spring-boot-starter-quartz')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('com.fasterxml.jackson.module:jackson-module-kotlin')
    compile('com.vaadin:vaadin-spring-boot-starter')
    compile('org.flywaydb:flyway-core')
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    compile("org.jetbrains.kotlin:kotlin-reflect")

    compile("com.h2database:h2")

    compile("eu.vaadinonkotlin:vok-rest:0.6.2")
    compile('org.codehaus.groovy:groovy-all:2.5.4')
    compile("org.flywaydb:flyway-core:5.2.0")

    compile "org.grails:gorm-hibernate5-spring-boot:6.1.6.RELEASE"
    compile "org.hibernate:hibernate-core:5.1.0.Final"
    compile "org.hibernate:hibernate-ehcache:5.1.0.Final"

    runtime "org.apache.tomcat:tomcat-jdbc:8.5.0"
    runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0"
    runtime "org.slf4j:slf4j-api:1.7.10"

}

就这么简单,项目无法启动。究竟是什么导致了 UnsatisfiedDependencyException?有没有简单直接的方法来解决它?

非常感谢您提前。

标签: springgradlegroovykotlingrails-orm

解决方案


推荐阅读