akourt
akourt

Reputation: 5563

Problems with Micronaut Data

I am currently in the process of upgrading an existing Micronaut application from version 1.2.x to 2.2.1 (latest) and I thought that it would also be a good idea to start using micronaut-data to perform whatever database interactions are required.

I have implemented all the various code changes and have also ported the code over to use Micronaut's own repositories but whenever I start the application, every time it attempts to perform any kind of database-related interaction it fails with the following error:

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)

I have followed the configuration guide found here regarding setting up Micronaut Data and I think I have imported all the correct dependencies https://micronaut-projects.github.io/micronaut-data/latest/guide/#introduction.

Documentation states that a transaction manager should be available automatically but this seems not to be the case.

For reference my build.gradle and application.yml looks like so:

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`}
---

Does anyone have a hint as to why this problem occurs?

Upvotes: 1

Views: 2655

Answers (1)

akourt
akourt

Reputation: 5563

After some digging around I noticed that the entity-scan.packages was pointing over to a wrong package (was repositories instead of entities). Correcting this resolved the issue, but still the exception messages produced under those cases are not very useful.

Upvotes: 1

Related Questions