Собственный образ данных Micronaut: не существует bean-компонента типа [io.micronaut.data.operations.PrimaryRepositoryOperations]

Я работаю над новым примером, используя 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]

Без native-образа работает отлично, тесты прошли:

./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).

Кажется, проблема неправильной конфигурации при переходе на собственный, но, поскольку я следую руководству и использую сгенерированное приложение, не знаю, чего не хватает.

1 ответ

Удаление параметра jpa package-to-scan из конфигурации помогло:

jpa:
  default:
    packages-to-scan:
      - 'mn.data.pg.domain'
Другие вопросы по тегам