1

我目前正在将现有的 Micronaut 应用程序从版本 1.2.x 升级到 2.2.1(最新),我认为开始使用它micronaut-data来执行所需的任何数据库交互也是一个好主意。

我已经实现了所有各种代码更改,并且还移植了代码以使用 Micronaut 自己的存储库,但是每当我启动应用程序时,每次它尝试执行任何与数据库相关的交互时都会失败并出现以下错误:

20:21:06.535 [scheduled-executor-thread-21] ERROR i.m.s.DefaultTaskExceptionHandler - Error invoking scheduled task for bean [fts.marketing.utils.$TestDefinition$Intercepted@122b3da3] No bean of type [io.micronaut.transaction.SynchronousTransactionManager] 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).
io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.transaction.SynchronousTransactionManager] 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).
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2322)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:721)
    at io.micronaut.transaction.interceptor.TransactionalInterceptor.lambda$intercept$0(TransactionalInterceptor.java:111)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
    at io.micronaut.transaction.interceptor.TransactionalInterceptor.intercept(TransactionalInterceptor.java:96)
    at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:82)
    at fts.marketing.utils.$TestDefinition$Intercepted.doSomething(Unknown Source)
    at fts.marketing.utils.$TestDefinition$$exec1.invokeInternal(Unknown Source)
    at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:146)
    at io.micronaut.inject.DelegatingExecutableMethod.invoke(DelegatingExecutableMethod.java:76)

我已按照此处找到的有关设置 Micronaut 数据的配置指南进行操作,并且我认为我已经导入了所有正确的依赖项https://micronaut-projects.github.io/micronaut-data/latest/guide/#introduction

文档指出事务管理器应该自动可用,但情况似乎并非如此。

供参考build.gradle,我application.yml看起来像这样:

dependencies {

    annotationProcessor 'org.projectlombok:lombok:1.18.8'
    annotationProcessor 'io.micronaut:micronaut-inject-java'
    annotationProcessor 'io.micronaut:micronaut-validation'
    annotationProcessor 'io.micronaut:micronaut-graal'
    annotationProcessor 'javax.persistence:javax.persistence-api:2.2'
    annotationProcessor 'io.micronaut.data:micronaut-data-processor'

    compileOnly 'org.projectlombok:lombok:1.18.8'

    /*** MICRONAUT ***/
    runtime 'io.micronaut.sql:micronaut-jdbc-hikari'
    implementation 'io.micronaut:micronaut-inject'
    implementation 'io.micronaut:micronaut-validation'
    implementation 'io.micronaut:micronaut-runtime'
    implementation 'io.micronaut.data:micronaut-data-hibernate-jpa'
    implementation 'io.micronaut.beanvalidation:micronaut-hibernate-validator'
    implementation 'io.micronaut.redis:micronaut-redis-lettuce'
    implementation 'io.micronaut.kafka:micronaut-kafka'
    implementation 'io.micronaut:micronaut-http-client'
    implementation 'io.micronaut:micronaut-management'
    implementation 'io.micronaut:micronaut-aop'

    /*** ADDITIONAL DEPENDENCIES ***/
    runtime 'com.oracle:ojdbc7:12.1.0.1.0'
    runtime "ch.qos.logback:logback-classic:1.2.3"
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'org.apache.commons:commons-text:1.6'
    implementation 'commons-codec:commons-codec:1.9'
    implementation 'net.htmlparser.jericho:jericho-html:internal'
    implementation 'org.atteo:evo-inflector:1.2.2'
    implementation 'com.sun.mail:javax.mail:1.6.2' // TODO: Use only SMTP provider to reduce bundle size
    implementation 'org.freemarker:freemarker:2.3.28'
    implementation "ch.qos.logback.contrib:logback-jackson:0.1.5"
    implementation "ch.qos.logback.contrib:logback-json-classic:0.1.5"
    implementation "org.codehaus.janino:janino:3.1.0"

    /*** TEST DEPENDENCIES ***/
    testAnnotationProcessor "io.micronaut:micronaut-inject-java"
    testRuntime "org.junit.jupiter:junit-jupiter-engine"
    testRuntime "com.h2database:h2"
    testImplementation "org.junit.jupiter:junit-jupiter-api"
    testImplementation "org.junit.jupiter:junit-jupiter-params"
    testImplementation "io.micronaut.test:micronaut-test-junit5"
    testImplementation 'org.apache.kafka:kafka-clients:2.3.0:test'
    testImplementation 'org.apache.kafka:kafka_2.12:2.3.0'
    testImplementation 'org.apache.kafka:kafka_2.12:2.3.0:test'
    testImplementation "com.github.kstyrc:embedded-redis:0.6"
    testImplementation "org.mockito:mockito-core:3.0.0"
    testImplementation "org.mockito:mockito-junit-jupiter:3.0.0"
    
}
---
datasources:
  default:
    url: ${JDBC_URL}
    username: ${JDBC_USER}
    password: ${JDBC_PASSWORD}
    driverClassName: ${JDBC_DRIVER:oracle.jdbc.OracleDriver}
    dialect: oracle
    schema-generate: none
---
jpa:
  default:
    entity-scan:
      packages: 'fts.marketing.repositories'
    properties:
      hibernate:
        hbm2ddl:
          auto: none
        show_sql: true
        format_sql: true
        use_sql_comments: false
        dialect: ${JPA_DIALECT:`org.hibernate.dialect.Oracle12cDialect`}
---

有没有人暗示为什么会出现这个问题?

4

1 回答 1

1

经过一番挖掘后,我注意到entity-scan.packages指向错误的包(是repositories而不是entities)。纠正这个问题解决了这个问题,但在这些情况下产生的异常消息仍然不是很有用。

于 2020-12-17T08:59:16.720 回答