我正在使用 Micronaut、Micronaut Data、JPA、Postgres 和 GraalVM 开发一个新示例,遵循 https://github.com/rmondejar/micronaut-postgres-example
此示例是使用具有以下功能的 Micronaut Launch 2.0.0.RC1 创建的:
[annotation-api, app-name, data, data-jpa, docker, file-watch, flyway, graalvm, gradle, hibernate-jpa, http-client, java, java-application, jdbc-hikari, logback, netty-server, postgres, readme, security-annotations, security-jwt, shade, spock, testcontainers, yaml]
没有本机图像,它可以完美运行,测试通过:
./gradlew test
(...)
24 passing (35.2s)
BUILD SUCCESSFUL in 43s
4 actionable tasks: 4 executed
生成本机映像并执行它看起来不错:
$ ./gradlew assemble
$ native-image --no-server -cp build/libs/mn-data-pg-*-all.jar
$ ./mn-data-pg
21:51:37.256 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
21:51:37.286 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
21:51:37.287 [main] INFO i.m.flyway.AbstractFlywayMigration - Running migrations for database with qualifier [default]
21:51:37.287 [main] INFO o.f.c.i.license.VersionPrinter - Flyway Community Edition 6.4.3 by Redgate
21:51:37.290 [main] INFO o.f.c.i.database.DatabaseFactory - Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 12.3)
21:51:37.318 [main] INFO o.f.core.internal.command.DbValidate - Successfully validated 2 migrations (execution time 00:00.011s)
21:51:37.328 [main] INFO o.f.core.internal.command.DbMigrate - Current version of schema "public": 1.1
21:51:37.330 [main] INFO o.f.core.internal.command.DbMigrate - Schema "public" is up to date. No migration necessary.
21:51:37.349 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 128ms. Server Running: http://localhost:8080
但是,一旦到达存储库,它总是会失败:
$ curl -d '{"username":"user1", "password":"password1"}' -H "Content-Type: application/json" -H "Authorization: Basic dXNlcjE6cGFzc3dvcmQx" -X POST http://127.0.0.1:8080/login
Unexpected error occurred: No backing RepositoryOperations configured for repository. Check your configuration and try again
io.micronaut.context.exceptions.ConfigurationException: No backing RepositoryOperations configured for repository. Check your configuration and try again
at io.micronaut.data.intercept.DataIntroductionAdvice.findInterceptor(DataIntroductionAdvice.java:124)
at io.micronaut.data.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:78)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:69)
at io.micronaut.validation.ValidatingInterceptor.intercept(ValidatingInterceptor.java:106)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:69)
at mn.data.pg.repositories.UserRepository$Intercepted.findByUsername(Unknown Source)
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.data.operations.PrimaryRepositoryOperations] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
转到本机时似乎是配置错误的问题,但是由于我遵循指南并使用生成的应用程序,因此不确定缺少什么。