https://github.com/rmondejar/micronaut-postgres-exampleに従って、Micronaut、Micronaut Data、JPA、Postgres、および GraalVM を使用して新しい例に取り組んでいます 。
この例は、次の機能を備えた 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).
ネイティブにすると設定ミスの問題のようですが、ガイドに従って生成されたアプリケーションを使用しているため、何が欠けているのかわかりません。