简体   繁体   English

将外部jar中的orm xml加载到Spring Boot中

[英]Load orm xml from External Jar into Spring Boot

I have a maven spring project called core-project jar which has orm and persistence xml files and defined entities both in Annotation and xml. 我有一个名为core-project jar的maven spring项目,它包含orm和persistence xml文件以及Annotation和xml中定义的实体。 Now I have another spring boot project which utilizes this core project to initialize persistence with. 现在我有另一个spring boot项目,它利用这个核心项目来初始化持久性。 I am able to get the annotated entities(ie with @Entity ) scanned when defining @EntityScan(packages) in SpringBoot Main class but none of the entities are scanned which are defined in orm xml (ie <entity> ). 在SpringBoot Main类中定义@EntityScan(包)时,我能够扫描带注释的实体(即使用@Entity ),但是没有扫描在orm xml中定义的<entity> (即<entity> )。

Getting error as Unable to locate persister for entity 将错误视为Unable to locate persister for entity

But when I run the same project as mvn spring-boot:run , everything runs like charm. 但是当我运行与mvn spring-boot:run相同的项目时,一切都像魅力一样运行。 When I do a java -jar I end up in above issue. 当我做一个java -jar时,我最终遇到了上述问题。

I have tried setting up LocalContainerEntityManagerFactoryBean and setting packages to scan but no luck. 我已经尝试设置LocalContainerEntityManagerFactoryBean并设置包来扫描但没有运气。

Let me know what needs to done for a spring boot to load orm xml based entities from external jar. 让我知道弹簧启动需要做什么才能从外部jar加载基于xml的实体。

Note: orm and persistence xmls are part of core-project, we dont want it in spring boot project. 注意:orm和persistence xmls是core-project的一部分,我们不想在spring boot项目中使用它。

You could try to create a persistence.xml in the Spring Boot project to reference the jar file: 您可以尝试在Spring Boot项目中创建一个persistence.xml来引用jar文件:

<jar-file>core.jar</jar-file> 

I never done that with spring boot but maybe this works as well as with "normal" Java EE apps. 我从来没有用spring boot做过,但也许这与“普通”Java EE应用程序一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM