在一个项目中,我们使用Hibernate和HikariCP,它在Eclipse中运行良好。但是一旦我生成一个jar文件(Maven),就不能再找到hikaricp了。我已经在每个可能的角度转变了这一点,但我无法弄清楚出了什么问题......
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="starmap" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>net.clanwolf.c3.transfer.pojos.User</class>
<class>net.clanwolf.c3.transfer.pojos.RolePlayStory</class>
<class>net.clanwolf.c3.transfer.pojos.RolePlayCharacter</class>
<class>net.clanwolf.c3.transfer.pojos.RolePlayStoryVar2</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://**.**.**.**:3306/C3?useUnicode=yes&characterEncoding=UTF-8" />
<property name="current_session_context_class" value="thread" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<!-- Hikari connection pool -->
<property name="hibernate.hikari.dataSource.url" value="jdbc:mysql://**.**.**.**:3306/C3?useUnicode=yes&characterEncoding=UTF-8" />
<property name="hibernate.hikari.dataSource.user" value="**"/>
<property name="hibernate.hikari.maximumPoolSize" value="100" />
<property name="hibernate.hikari.idleTimeout" value="30000" />
<property name="hibernate.hikari.dataSource.cachePrepStmts" value="true" />
<property name="hibernate.hikari.dataSource.prepStmtCacheSize" value="250" />
<property name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit" value="2048" />
<property name="hibernate.hikari.dataSource.useServerPrepStmts" value="true" />
</properties>
</persistence-unit>
</persistence>
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<dependencies>
<!-- Database persistence -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- <version>5.1.33</version> -->
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
<!-- <version>5.0.3.Final</version> -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.1.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-hikaricp -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-hikaricp</artifactId>
<version>5.2.7.Final</version>
</dependency>
...
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
<!--@Transactional -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
...
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
...
</dependencies>
</project>
如果我在Eclipse中运行它,那就没关系了:
01:14:05,436 INFO HikariDataSource:70 - HikariPool-1 - 已开始。
如果我从创建jar运行它,它会说:
01:11:14,631 WARN ConnectionProviderInitiator:256 - HHH000472:Hikari 遇到了属性,但Hikari ConnectionProvider却没有 在类路径上找到;这些属性将被忽略。 01:11:14,634 WARN连接:71 - HHH10001002:使用Hibernate 内置连接池(不供生产使用!)01:11:14,639 INFO 连接:127 - HHH10001005:使用驱动程序[com.mysql.cj.jdbc.Driver] 在URL [JDBC:MySQL的://212.227.253.80:3306 / C3了useUnicode = YES&安培;的characterEncoding = UTF-8]
文件IS在类路径中是肯定的,我不明白为什么它不会被找到。 非常感谢任何帮助!
答案 0 :(得分:0)
解决。
我的项目是用maven-shade构建的。显然,如果hikariCP作为类文件(而不是jar)包含在生成的jar包中,它根本不起作用。如果我在我的jar旁边的文件系统中提供CP jar并将它们添加到清单中,则会找到它们。
我不知道为什么它不会只是首先使用包中的类文件,但是......它们在那些文件中并且它们位于正确的位置,但是hikari不会看到它们。