您需要一个类定义来挂起它
@import(其他在类上而不是在接口上的注释是多余的)。
更新: 并且
(更重要的是)除非它们实际上在文件中,否则Hibernate无法找到带注释的类(它注释性地分析字节码而不是类定义)。因此,您可以通过加扰并以这种方式运行它来使您的应用工作:
$ spring jar app.jar app.groovy$ java -jar app.jar
这是该应用程序的较短版本,其工作方式与删除所有多余内容的方式相同:
package bookapp@Grab("spring-boot-starter-data-jpa")@Grab("spring-boot-starter-data-rest")@Grab("h2")import org.springframework.data.rest.core.annotation.RepositoryRestResourceimport org.springframework.data.repository.CrudRepositoryimport javax.persistence.*@Configurationclass App {}@RepositoryRestResource(path = "authors")interface AuthorRepository extends CrudRepository<Author, Long> {}@Entityclass Author { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id String firstname String lastname}


