Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I've created a sample project with two modules:
Please find below the codebase of this project (you can also find it here).
When I run this project with IntelliJ or Eclipse, everything works as expected.
When I package this same project as a fat jar, then I try to run it, I am getting an
IllegalArgumentException: Unable to locate persister.
I noticed that, on startup, a call is made to method
and this method is returning /Users/mabbas/example-project-parent/example-project-boot/target/example-project-boot-0.0.1-SNAPSHOT.jar
/Users/mabbas/example-project-parent/example-project-boot/target/example-project-boot-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/example-project.jar (the root of persist.xml is example-project and not example-project-boot).
Because of this result, I think that the entity defined inside example-project.jar is never loaded and then the exception is thrown.
I have first created a spring-boot issue here, but it seems that this problem is more about spring-orm than spring-boot.
Thanks in advance,
Reference URL: spring-projects/spring-boot#11144
1 votes, 4 watchers
Stéphane Nicoll commented
Thanks for the sample.
That setup is super unusual, have you considered migrating it (i.e. let Spring Boot creates the datasource rather than doing everything yourself? or configure things at least in one place?). Looking at the code you are creating the entity manager in one module and the persistence unit in another. Yet the persistence unit is linked so you have an inverse dependency from a configuration standpoint.
The URL that is computed is actually correct (remember, it is a default URL that we compute as a fallback because JPA requires one). I've tried to force the use of
Mohamad ABBAS commented
Thank you, Stéphane for your comment.
I completely agree with you; it is super unusual. But unfortunately, in my real project, I have a dependency on three legacy JARs, each of them declares a persistent unit, and those JARs cannot be modified.
I made a test by intercepting the call, in my IDE, to method
and when i replace the result of this method with
it resolves the problem. This is why I was thinking about a bug in determinePersistenceUnitRootUrl.
As a workaround to this problem, and instead of building a fat jar, i can extract all the dependencies of my project to a 'lib' directory and point the classpath to this directory when running the application. It resolves my problem but of course, it is not the perfect solution.
Thomas Heigl commented
I ran into this issue with my app as well. I solved it by deleting all my
final LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource()); emf.setPackagesToScan("com.my.module1", "com.my.module2");