我试图在Wildfly Swarm应用程序中将SQLite数据库与Hibernate一起使用。我正在使用Swarm版本2018.5.0,据我了解,该版本基于Wildfly 11.0.0.Final。因此,我首先在Wildfly上完成了所有工作,然后尝试在Swarm上进行复制,但没有成功。
这是我在Wildfly上工作的目的
在Wilfly内部创建文件modules\system\layers\base\org\sqlite\main\module.xml
,其内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.5" name="org.sqlite">
<resources>
<resource-root path="sqlite-jdbc-3.23.1.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
也将文件sqlite-jdbc-3.23.1.jar
放在同一目录中。
编辑了standalone.xml
的本节:
<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<datasources>
[...]
<datasource jndi-name="java:/MyAppOfflineDS" pool-name="MyAppOfflineDS" enabled="true">
<connection-url>jdbc:sqlite:file:MyApp.db</connection-url>
<driver>sqlite</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
[...]
<driver name="sqlite" module="org.sqlite">
<driver-class>org.sqlite.JDBC</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
在我的Maven项目中使用以下内容创建文件src\main\resources\META-INF\persistence.xml
:
<persistence [...]
version="2.1">
<persistence-unit name="MyApp" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/MyAppOfflineDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
并将此依赖项添加到我的pom.xml
:
<dependency>
<groupId>com.zsoltfabok</groupId>
<artifactId>sqlite-dialect</artifactId>
<version>1.0</version>
</dependency>
一切正常,休眠功能全部正常。
这是我尝试在Swarm上运行的方法
按照此处的说明进行操作: https://howto.wildfly-swarm.io/create-a-datasource/
使用以下内容创建文件src\main\resources\project-defaults.yml
:
swarm:
datasources:
data-sources:
MyAppOfflineDS:
jndi-name: java:/MyAppOfflineDS
connection-url: jdbc:sqlite:file:MyApp.db
driver-name: sqlite
user-name: sa
password: sa
jdbc-drivers:
sqlite:
driver-module-name: org.sqlite
driver-class-name: org.sqlite.JDBC
将此依赖项添加到我的pom.xml
:
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
但是当我尝试运行时,出现以下错误:
2018-06-30 10:57:21,154 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 21) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "sqlite")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.sqlite]"
[...]
2018-06-30 10:57:22,748 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MyAppOfflineDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.sqlite"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.MyAppOfflineDS is missing [jboss.jdbc-driver.sqlite]",
"jboss.driver-demander.java:/MyAppOfflineDS is missing [jboss.jdbc-driver.sqlite]"
]
}