我有很多机器,相同。所有都运行Tomcat 8.5.31和java 1.8.0_171-b11
我有一个创建实体管理器的数据库类。我在所有可以运行的机器上从CDI调用该类。
该方法调用createEntityManagerFactory(" jdbc / mydatabase")
然后我使用web.xml中定义的侦听器调用相同的方法,并且它再次起作用,但仅在某些机器上,完全相同.war
我能找到的唯一区别是,它没有运行Bitdefender的机器吗?
在它不起作用的机器上,我得到以下空指针
java.lang.NullPointerException
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getProviderNames(PersistenceProviderResolverHolder.java:197)
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:112)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:76)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.tillsystem.managers.DatabaseManager.getEntityManageriTill(DatabaseManager.java:55)
at com.tillsystem.managers.DatabaseManager.getTableTransactionsIds(DatabaseManager.java:245)
at com.tillsystem.sync.SyncService.downloadTransactions(SyncService.java:249)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
答案 0 :(得分:0)
我通过在类的构造函数中手动创建PersistenceProviderResolver来修复此问题
PersistenceProviderResolverHolder.setPersistenceProviderResolver(new PersistenceProviderResolver() {
private List<PersistenceProvider> providers = new ArrayList<PersistenceProvider>();
@Override
public List<PersistenceProvider> getPersistenceProviders() {
org.eclipse.persistence.jpa.PersistenceProvider provider = new org.eclipse.persistence.jpa.PersistenceProvider();
providers.add(provider);
return providers;
}
@Override
public void clearCachedProviders() {
providers.clear();
}
});
properties.put(PersistenceUnitProperties.CLASSLOADER, getClass()
.getClassLoader());