在我的Java项目中:
在build.gradle中:
plugins {
id 'groovy'
id 'java'
}
group 'shopping'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
implementation 'javax.persistence:javax.persistence-api:2.2'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.data:spring-data-jpa:1.0.0.RELEASE'
implementation group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.2.2.RELEASE', ext: 'pom'
runtimeOnly 'com.h2database:h2'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
在Java文件中:
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner bookDemo(BookRepository bookRepository) {
return (args) -> {
但是我得到了编译错误:
@SpringBootApplication - can't not resolve
CommandLineRunner - can't not resolve