Spring boot 弹簧靴2.0.0.M7,Kotlin,Gradle-bean和x27;找不到
我试图运行一个用Kotlin编写并用Gradle构建的小型Spring启动应用程序。在IntelliJ中运行应用程序时,我收到以下消息:Spring boot 弹簧靴2.0.0.M7,Kotlin,Gradle-bean和x27;找不到,spring-boot,kotlin,Spring Boot,Kotlin,我试图运行一个用Kotlin编写并用Gradle构建的小型Spring启动应用程序。在IntelliJ中运行应用程序时,我收到以下消息: 应用程序无法启动 说明: com.mycompany.app.rest.api.MyApi中构造函数的参数1 需要类型为“com.mycompany.app.domain.UserRepository”的bean 找不到 行动: 考虑定义类型为的bean 配置中的“com.mycompany.app.domain.UserRepository” MyAPP
应用程序无法启动
说明: com.mycompany.app.rest.api.MyApi中构造函数的参数1 需要类型为“com.mycompany.app.domain.UserRepository”的bean 找不到 行动: 考虑定义类型为的bean 配置中的“com.mycompany.app.domain.UserRepository” MyAPP:
Myapp.kt
UserRepository.kt
package com.mycompany.app.domain
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface UserRepository: JpaRepository<User, String> {
}
我试图将MyApp.kt移动到com.mycompany.app中的上述目录,但没有成功。您必须将
@EnableJpaRepositories
和@EntityScan
添加到您的MyApp
类中
@SpringBootApplication
@ComponentScan(basePackages = arrayOf("com.mycompany.app"))
@EnableJpaRepositories(basePackages = arrayOf("com.mycompany.app.domain"))
@EntityScan(value = "com.mycompany.app.domain")
class MyApp
您必须将
@EnableJpaRepositories
和@EntityScan
添加到您的MyApp
-类中
@SpringBootApplication
@ComponentScan(basePackages = arrayOf("com.mycompany.app"))
@EnableJpaRepositories(basePackages = arrayOf("com.mycompany.app.domain"))
@EntityScan(value = "com.mycompany.app.domain")
class MyApp
将主类移动到package
com.mycompany.app
,它应该开始工作。正如我在原始帖子中提到的,我已经尝试过这个,但没有成功。将主类移动到packagecom.mycompany.app
,它应该开始工作。正如我在原始帖子中提到的,我尝试过这个,但没有成功。谢谢。它对我有用。我正在寻找Spring引导文档,但不清楚@EnableJpaRepositories设置的义务。会话77.3在文档中使用Spring数据存储库。@etc如果这个答案对您有帮助,请接受这个答案,这也会对其他SOER有帮助。谢谢。它对我有用。我正在寻找Spring引导文档,但不清楚@EnableJpaRepositories设置的义务。会话77.3在文档中使用Spring数据存储库。@etc如果这个答案对您有所帮助,请接受这个答案,这也会对其他SOER有所帮助。
package com.mycompany.app.domain
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface UserRepository: JpaRepository<User, String> {
}
buildscript {
ext {
kotlinVersion = '1.2.10'
springBootVersion = '2.0.0.M7'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
repositories {
mavenCentral()
mavenLocal()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("com.fasterxml.jackson.module:jackson-module-kotlin")
compile("org.springframework.boot:spring-boot-starter-undertow")
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.kafka:spring-kafka')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.10")
compile("org.jetbrains.kotlin:kotlin-reflect")
compile("com.h2database:h2")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('io.projectreactor:reactor-test')
}
@SpringBootApplication
@ComponentScan(basePackages = arrayOf("com.mycompany.app"))
@EnableJpaRepositories(basePackages = arrayOf("com.mycompany.app.domain"))
@EntityScan(value = "com.mycompany.app.domain")
class MyApp