为啥 Wildfly 10 在部署时给我“jdbc:postgresql 不允许空名称段”?

Posted

技术标签:

【中文标题】为啥 Wildfly 10 在部署时给我“jdbc:postgresql 不允许空名称段”?【英文标题】:Why Wildfly 10 gives me "Empty name segment is not allowed for jdbc:postgresql" at deploy?为什么 Wildfly 10 在部署时给我“jdbc:postgresql 不允许空名称段”? 【发布时间】:2017-06-10 14:51:45 【问题描述】:

我有一个将 ejb 模块打包到一个 ear 文件中的应用程序。当我想部署到 Wildfly 时,我收到以下错误。根据this post,standalone.xml 文件有些问题。我已经检查过了,没问题。

谁能告诉我这里有什么问题?

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="PU" transaction-type="JTA">
        <jta-data-source>jdbc:postgresql://localhost:5432/Database</jta-data-source>
        <properties>
            <property name="hibernate.connection.username" value="postgres"/>
            <property name="hibernate.connection.password" value="postgres" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
        </properties>
    </persistence-unit>
</persistence>

Wildfly 控制台日志。

16:41:50,200 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.subunit."DigitalLibrary.MasterData.Dataservice.ear"."MasterData.Ejb.jar".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."DigitalLibrary.MasterData.Dataservice.ear"."MasterData.Ejb.jar".FIRST_MODULE_USE: WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of subdeployment "MasterData.Ejb.jar" of deployment "DigitalLibrary.MasterData.Dataservice.ear"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Empty name segment is not allowed for jdbc:postgresql:
        at org.jboss.msc.service.ServiceName.of(ServiceName.java:90)
        at org.jboss.msc.service.ServiceName.append(ServiceName.java:117)
        at org.jboss.as.naming.deployment.ContextNames.buildServiceName(ContextNames.java:203)
        at org.jboss.as.naming.deployment.ContextNames$BindInfo.<init>(ContextNames.java:215)
        at org.jboss.as.naming.deployment.ContextNames$BindInfo.<init>(ContextNames.java:206)
        at org.jboss.as.naming.deployment.ContextNames.bindInfoFor(ContextNames.java:136)
        at org.jboss.as.naming.deployment.ContextNames.bindInfoForEnvEntry(ContextNames.java:190)
        at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deployPersistenceUnitPhaseOne(PersistenceUnitServiceHandler.java:502)
        at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.addPuService(PersistenceUnitServiceHandler.java:276)
        at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.handleJarDeployment(PersistenceUnitServiceHandler.java:163)
        at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deploy(PersistenceUnitServiceHandler.java:133)
        at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:52)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
        ... 5 more

【问题讨论】:

jta-data-source 应该包含数据源的 JNDI 名称,而不是 JDBC url 【参考方案1】:

“jta-data-source 指向该持久性单元映射到的数据库的 JNDI 名称。”来自链接https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ch01s02s01.html

但是您已经配置了连接 U​​RL。可以从 jboss 管理页面或通过修改独立文件来配置数据源。一个例子——https://developer.jboss.org/wiki/JBossAS7-DatasourceConfigurationForPostgresql?_sscc=t

【讨论】:

以上是关于为啥 Wildfly 10 在部署时给我“jdbc:postgresql 不允许空名称段”?的主要内容,如果未能解决你的问题,请参考以下文章

为啥我的编译器在 c++ 中使用动态分配的内存时给我错误

Infinispan/JDBC 作为 Wildfly/JBoss 上 Hibernate Search 的后端

wildfly 部署war包standalone 部署为啥要 war.deployed

JBoss 5.1.0 到 Wildfly

Wildfly 10.1 部署后停止部署

在 Wildfly 10 上部署 Vue.js