因此,我定义了一个自定义数据源来连接到我的MySQL数据库,但是在启动时,Wildfly Swarm给了我以下错误:
2018-09-27 10:37:23,213错误 [org.jboss.as.controller.management-operation](主要)WFLYCTL0013: 操作(“ add”)失败-地址:((“ deployment” => “ my-application.war”))-失败描述:{ “ WFLYCTL0412:未安装的必需服务:” => [“ jboss.naming.context.java.jboss.CustomDS”], “ WFLYCTL0180:服务缺少/不可用的依赖项” => [ “ jboss.persistenceunit。\” my-application.war#my-application \“丢失[jboss.naming.context.java.jboss.CustomDS]”, “ jboss.persistenceunit。\” my-application.war#my-application \“。 FIRST_PHASE 缺少[jboss.naming.context.java.jboss.CustomDS]“ ]} 2018-09-27 10:37:23,218错误[org.jboss.as.server](主)WFLYSRV0021:部署了“ my-application.war”部署 返回并显示以下失败消息:{ “ WFLYCTL0412:未安装的必需服务:” => [“ jboss.naming.context.java.jboss.CustomDS”], “ WFLYCTL0180:服务缺少/不可用的依赖项” => [ “ jboss.persistenceunit。\” my-application.war#my-application \“丢失[jboss.naming.context.java.jboss.CustomDS]”, “ jboss.persistenceunit。\” my-application.war#my-application \“。 FIRST_PHASE 缺少[jboss.naming.context.java.jboss.CustomDS]“ ]}
我的配置如下:
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="primary" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/CustomDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.default_batch_fetch_size" value="16" />
<property name="hibernate.jdbc.batch_size" value="100" />
<property name="hibernate.order_inserts" value="true" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.id.new_generator_mappings" value="true" />
<property name="hibernate.connection.requireSSL" value="false" />
<property name="hibernate.jdbc.time_zone" value="CEST"/>
</properties>
</persistence-unit>
</persistence>
standalone.xml
<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<xa-datasource jdni-name="java:jboss/datasources/CustomDS" pool-name="CustomDS">
<driver>mysql</driver>
<xa-datasource-property name="ServerName">localhost</xa-datasource-property>
<xa-datasource-property name="DatabaseName">mydb</xa-datasource-property>
<security>
<user-name>someusername</user-name>
<password>somepassword</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"></valid-connection-checker>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"></exception-sorter>
</validation>
</xa-datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
我尝试了所有操作,包括手动部署MySQL驱动程序,但是似乎没有任何效果……有什么建议吗?我需要定义一些创建web.xml文件的内容吗?