8

当我尝试使用内存 h2 数据库和 Jpa 配置 micronaut-data 时,出现以下异常。
我一直在关注文档

我使用 maven 作为构建工具从命令行创建了项目。我有以下

<dependency>
     <groupId>io.micronaut.configuration</groupId>
      <artifactId>micronaut-jdbc-tomcat</artifactId>
      <scope>runtime</scope>
    </dependency>
<dependency>
     <groupId>com.h2database</groupId>
     <artifactId>h2</artifactId>
     <scope>runtime</scope>
</dependency>
<dependency>
     <groupId>io.micronaut.data</groupId>
     <artifactId>micronaut-data-hibernate-jpa</artifactId>
     <version>1.0.0.M3</version>
</dependency>

而且我还添加了这样的注释处理器

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
   ......
  <configuration>
    ...
    <annotationProcessorPaths>
      <path>
        <groupId>io.micronaut</groupId>
        <artifactId>micronaut-inject-java</artifactId>
        <version>${micronaut.version}</version>
      </path>
      <path>
        <groupId>io.micronaut</groupId>
        <artifactId>micronaut-validation</artifactId>
        <version>${micronaut.version}</version>
      </path>
      <path>
        <groupId>io.micronaut.data</groupId>
        <artifactId>micronaut-data-processor</artifactId>   
        <version>1.0.0.M3</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
  .....
</plugin>

我的 Entity 类和 Repository 类与指南中提到的完全一样。当我尝试使用存储库进行保存时,出现此异常

18:16:37.787 [pool-1-thread-3] ERROR i.m.h.s.netty.RoutingInBoundHandler - 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
..............................
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.data.operations.RepositoryOperations] 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).

我已经调查过。这是完全不同的,它对我的​​问题没有帮助。

有趣的是,如果我改变 micronaut 数据注释过程的顺序或者我的意思是如果我这样放

<plugin>                                                    
  <groupId>org.apache.maven.plugins</groupId>               
  <artifactId>maven-compiler-plugin</artifactId>            
   ......                                                   
  <configuration>                                           
    ...                                                     
    <annotationProcessorPaths>                              
      <path>                                                
        <groupId>io.micronaut</groupId>                     
        <artifactId>micronaut-inject-java</artifactId>      
        <version>${micronaut.version}</version>             
      </path>                                               
      <path>                                                
        <groupId>io.micronaut</groupId>                     
        <artifactId>micronaut-validation</artifactId>       
        <version>${micronaut.version}</version>             
      </path>                                               
      <path>                                                
        <groupId>io.micronaut.data</groupId>                
        <artifactId>micronaut-data-processor</artifactId>   
        <version>1.0.0.M3</version>                         
      </path>                                               
    </annotationProcessorPaths>                             
  </configuration>                                          
  .....                                                     
</plugin>  

我得到一个不同的例外。

Internal Server Error: All possible Introduction advise exhausted and no implementation found for method: Iterable saveAll(Iterable entities) 

任何指针都非常感谢。

4

3 回答 3

7

我收到此错误,我的情况的解决方案是将以下内容添加到application.yml

jpa:
  default:
    properties:
      hibernate:
        bytecode:
          provider: none

这是基于此处的示例项目:https ://github.com/micronaut-projects/micronaut-data/blob/v1.0.0.M3/examples/example-jpa/src/main/resources/application.yml#L15

于 2019-10-21T23:53:59.310 回答
2

文档不完整。对文档更新进行了拉取请求(https://github.com/micronaut-projects/micronaut-data/pull/197 )。它已被接受。更新的文档可以在这里找到

需要另一个依赖才能工作

<dependency>
    <groupId>io.micronaut.data</groupId>
    <artifactId>micronaut-data-hibernate-jpa</artifactId>
</dependency>
于 2020-03-30T10:20:19.987 回答
1

将模型实体包路径添加到application.yml

jpa:
default:
packages-to-scan:
  - 'com.entity' 

请在 yml 文件中添加组件扫描路径,因为应用实体无法找到

于 2021-02-16T09:26:10.493 回答