micronaut数据问题

93ze6v8z  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(453)

我目前正在将现有的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`}
---

有人知道为什么会出现这个问题吗?

ssgvzors

ssgvzors1#

在四处挖掘之后,我注意到 entity-scan.packages 指向一个错误的包裹 repositories 而不是 entities ). 更正此问题解决了问题,但在这些情况下生成的异常消息仍然不是很有用。

相关问题