如何从另一个JAR的外部类中使用JPA实体创建Micronaut项目
- 我有一个Micronaut项目,并且我正在尝试使用我的外部实体类构建该项目,该类别是Spring JPA中添加了pom.xml中的依赖性,但我总是有一个错误:由:io引起。 micronaut.context.exceptions.configurationException:jpa配置找不到的实体:packages [packageName]
- ]我已经添加了我的实体jar a a依赖性的“ scope compile”,
- [失败 ]已经创建了一个使用“ @intropsected(class = user.class)”的类文件。无法使用
- [失败]我还将 @entity和@intropstect在同一类中,如果可以确定实体类,但是它不起作用
- [失败]我也尝试创建一个AnnotationMapper,这将自动化映射带有“ javax.persistence.entity”的包装,请参阅参考 https://github.com/micronaut-projects/micronaut-projects/micronaut-core/micronaut-core/micronaut-core/blob/blob/blob/blob/3.5.x/inject/inject/src/src/src/mmain/src/mmain/src/mmsain/java/ io/micronaut/indect/beans/visitor/entityreflectiveccessannotationmapper.java
- 删除依赖依赖性micronaut-data-spring-jpa不需要我一个实体类。
注意:在我的Micronaut项目中,我没有@Entity类,因为我想使用我完成的Spring JPA实体类的外部罐子,以便可以将其重复使用其他应用程序。
编辑:MVN清洁安装或以日志运行:
io.micronaut.context.exceptions.beaninStantiationException: bean定义[org.hibernate.sessionfactory]无法加载:错误实例化bean类型[org.hibernate.boot.sessionfactorybuilder]
消息:jpa配置找不到的实体:packages [packagename]中找不到'default'。检查您是否已正确指定了一个包含JPA实体的软件包。 “ foo.bar”,纳入= entity.class)在您的申请类中声明 所需的路径:sessionFactory.hibernateSessionFactory(SessionFactoryBuilder sessionFactoryBuilder) - > sessionFactory.hibernateSessionFactory([SessionFactoryBuilder session factorybuilder]) - > sessionFactoryBuilder.HibernateSessionFactoryBuilder([元数据元数据],valioratorFactory validatorFactory,Interceptor HibernateInterceptor)
- I have a Micronaut project, and I'm trying to build the project with my external Entity classes which are in Spring JPA added on dependency in pom.xml, but I'm always having an error: Caused by: io.micronaut.context.exceptions.ConfigurationException: Entities not found for JPA configuration: 'default' within packages [packageName]
- [Failed] I have already added my Entity jar a dependency with "scope compile" in pom.xml
- [Failed] Already created a class file with "@Introspected(classes = User.class)", the User.class resides in my external Entity jar, as per micronaut documentation we can use the already compile classes by adding the annonation @Introspected, but this doesn't work
- [Failed] I also combine the @Entity and @Introspected at the same class if this can determine the Entity class, but it doesn't work
- [Failed] I also tried to create an AnnotationMapper, this will automate the mapping of package with "javax.persistence.Entity", see a reference https://github.com/micronaut-projects/micronaut-core/blob/3.5.x/inject/src/main/java/io/micronaut/inject/beans/visitor/EntityReflectiveAccessAnnotationMapper.java
- removing dependency micronaut-data-spring-jpa doesn't requires me an Entity class, but the auto migration of Micronaut to Spring JPA repository will be having an error.
Note: In my Micronaut project, I don't have @Entity classes, since I want to use the external jar of Spring JPA Entity classes that I made so I can reuse it to other applications.
Edit: mvn clean install or run as log:
io.micronaut.context.exceptions.BeanInstantiationException:
Bean definition [org.hibernate.SessionFactory] could not be loaded: Error instantiating bean of type [org.hibernate.boot.SessionFactoryBuilder]
Message: Entities not found for JPA configuration: 'default' within packages [packageName]. Check that you have correctly specified a package containing JPA entities within the "jpa.default.entity-scan.packages" property in your application configuration and that those entities are either compiled with Micronaut or a build time index produced with @Introspected(packages="foo.bar", includedAnnotations=Entity.class) declared on your Application class
Path Taken: SessionFactory.hibernateSessionFactory(SessionFactoryBuilder sessionFactoryBuilder) --> SessionFactory.hibernateSessionFactory([SessionFactoryBuilder sessionFactoryBuilder]) --> SessionFactoryBuilder.hibernateSessionFactoryBuilder([MetadataSources metadataSources],ValidatorFactory validatorFactory,Interceptor hibernateInterceptor)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我为解决自己的问题所做的:
要生成工作空间(就像 https://start.spring.io/ for Spring)
This is what I did to resolve my own issue:
to generate the workspace (its like https://start.spring.io/, for spring)
我遇到了同样的问题,然后我就解决了:
@introppected(class = {entity} .class)
在您的 application.java class micronaut的类别proj这将导入您的实体类,并使 jpa 将其识别为 jpa entity 。
只是一个提醒:您必须将{entity}类带有
@entity
从I had the same problem and I solved it like this:
@Introspected(classes={Entity}.class)
on your Application.java class of your Micronaut ProjThis will import your entity class and make JPA to recognise it as a JPA Entity.
Just a reminder: You must have your {Entity} class annotated with
@Entity
from