Как решить ошибку Spring: «требуется компонент с именем entityManagerFactory, который не может быть найден»? - PullRequest
0 голосов
/ 21 декабря 2018

Я пытаюсь интегрировать Vaadin Flow + Spring + Kotlin в мой проект, но, когда я просто пытаюсь запустить его, я получаю:

*************************** 
APPLICATION FAILED TO START 
*************************** 

Description:    

Parameter 0 of constructor in hello.CustomerController required a bean named 'entityManagerFactory' that could not be found.

И у меня всего 4 файла в моем проекте:

build.gradle.kts

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    val kotlinVersion = "1.2.41"
    id("org.springframework.boot") version "2.0.2.RELEASE"
    id("org.jetbrains.kotlin.jvm") version kotlinVersion
    id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
    id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
    id("io.spring.dependency-management") version "1.0.5.RELEASE"
}

version = "1.0.0-SNAPSHOT"

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

val test by tasks.getting(Test::class) {
    useJUnitPlatform()
}

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-quartz")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("com.vaadin:vaadin-spring-boot-starter:12.0.0")
    compile("org.flywaydb:flyway-core")
    compile("mysql:mysql-connector-java")
    compile("eu.vaadinonkotlin:vok-rest:0.6.2")
    compile ("org.codehaus.groovy:groovy-all:2.5.4")

    compile("org.grails:gorm-hibernate5-spring-boot:6.1.4.RELEASE")
    compile("org.hibernate:hibernate-core:5.3.7.Final")
    compile("org.hibernate:hibernate-ehcache:5.3.7.Final")
    compile("org.hibernate:hibernate-entitymanager:5.3.7.Final")

    runtimeOnly("org.springframework.boot:spring-boot-devtools")

    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("com.h2database:h2")
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    compile("org.jetbrains.kotlin:kotlin-reflect")
    compile("com.fasterxml.jackson.module:jackson-module-kotlin")
    testCompile("org.springframework.boot:spring-boot-starter-test") {
        exclude(module = "junit")
    }
    testImplementation("org.junit.jupiter:junit-jupiter-api")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

}

Customer.ktпакет привет

import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id

@Entity
data class Customer(
        val firstName: String,
        val lastName: String,
        @Id @GeneratedValue
        val id: Long = -1)

Application.kt

package hello

import org.slf4j.LoggerFactory
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean

@SpringBootApplication
class Application {

    private val log = LoggerFactory.getLogger(Application::class.java)

    @Bean
    fun init(repository: CustomerRepository) = CommandLineRunner {
            // save a couple of customers
            repository.save(Customer("Jack", "Bauer"))
    }

}

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

CustomerController.kt

package hello

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController

@RestController
class CustomerController(private val repository: CustomerRepository) {

    @GetMapping("/customers")
    fun findAll() = repository.findAll()

    @GetMapping("/customers/{lastName}")
    fun findByLastName(@PathVariable lastName:String)
            = repository.findByLastName(lastName)
}

Как вы можете видеть, это довольно простой проект, но я просто не могу запустить его из-за ошибки, которую он выдает.Я искал в Интернете, и я изменил build.gradle.kts и проект, и он просто не запускается.Любая идея, почему эта ошибка происходит?

Заранее спасибо.

...