PayaraMicro没有在WAR的glassfish-resources.xml中添加JDBC详细信息 [英] PayaraMicro is not adding jdbc details in glassfish-resources.xml from WAR

查看:114
本文介绍了PayaraMicro没有在WAR的glassfish-resources.xml中添加JDBC详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Payara Micro的docker容器中部署Web应用程序,但是 glassfish-resources.xml 详细信息未添加到服务器的 microdomain.xml

I have web app I'm trying to deploy in Payara Micro's docker container, but the glassfish-resources.xml details are not added to the server's microdomain.xml.

JDBC定义非常基本,它利用docker命令设置的环境变量(这是 MyApp.war / WEB-INF / glassfish中的位置) -resources.xml

The JDBC definition is pretty basic, utilizing environment variables set from the docker command (this is location in MyApp.war/WEB-INF/glassfish-resources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>

    <jdbc-resource pool-name="MyAppDB" jndi-name="jdbc/MyAppDB" enabled="true" ></jdbc-resource>


    <jdbc-connection-pool datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerDataSource" 
                          name="MyAppDB" 
                          res-type="javax.sql.DataSource">
      <property name="User" value="${ENV=MY_APP_DATABASE_USER}"></property>
      <property name="Password" value="${ENV=MY_APP_DATABASE_PASS}"></property>
      <property name="DatabaseName" value="${ENV=MY_APP_DATABASE_NAME}"></property>
      <property name="ServerName" value="${ENV=MY_APP_DATABASE_SERVER}"></property>
      <property name="PortNumber" value="1433"></property>
    </jdbc-connection-pool>    

</resources>

这是 payara.env 文件:

MY_APP_DATABASE_USER=someuser
MY_APP_DATABASE_PASS=somepass
MY_APP_DATABASE_NAME=MY_APP_DB
MY_APP_DATABASE_SERVER=192.168.10.110

从下面的日志中可以看到, mysql-jdbc-7.0。 0.jre8.jar 确实被添加到类路径中。

As you can see from the log below, mysql-jdbc-7.0.0.jre8.jar does get added to the classpath.

Docker命令:

docker run -p 8080:8080 \
           --mount type=bind,src=$(pwd)/deployments,dst=/opt/payara/deployments \
           --mount type=bind,src=$(pwd)/lib,dst=/opt/payara/lib \
           --env-file payara.env \
           --restart=always \
           payara/micro:5.191 \
           --addlibs /opt/payara/lib \
           --deploy /opt/payara/deployments/my-app.war \
           --contextroot ROOT

服务器输出(删除了多余的日志记录):

Server output (removed superfluous logging):

[2019-05-29T16:41:46.990+0000] [] [WARNING] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148106990] [levelValue: 900] Payara Micro Runtime directory is located in a temporary file location which can be cleaned by system processes.

[2019-05-29T16:41:47.034+0000] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148107034] [levelValue: 800] Payara Micro Runtime directory is located at /tmp/payaramicro-rt5934725251203193927tmp

[2019-05-29T16:41:47.061+0000] [] [INFO] [] [fish.payara.micro.boot.runtime.PayaraMicroRuntimeBuilder] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148107061] [levelValue: 800] Built Payara Micro Runtime

[2019-05-29T16:41:48.197+0000] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148108197] [levelValue: 800] Added /opt/payara/lib/mssql-jdbc-7.0.0.jre8.jar to classpath

[2019-05-29T16:41:50.422+0000] [] [INFO] [NCLS-CORE-00101] [javax.enterprise.system.core] [tid: _ThreadID=19 _ThreadName=RunLevelControllerThread-1559148109281] [timeMillis: 1559148110422] [levelValue: 800] Network Listener http-listener started in: 24ms - bound to [/0.0.0.0:8080]

[2019-05-29T16:41:50.572+0000] [] [INFO] [NCLS-CORE-00017] [javax.enterprise.system.core] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148110572] [levelValue: 800] Payara Micro  5.191 #badassmicrofish (94) startup time : Embedded (2,200ms), startup services(1,306ms), total(3,506ms)

[2019-05-29T16:41:53.520+0000] [] [INFO] [AS-WEB-GLUE-00198] [javax.enterprise.web] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148113520] [levelValue: 800] Created HTTP listener http-listener on host/port 0.0.0.0:8080

[2019-05-29T16:41:53.587+0000] [] [INFO] [AS-WEB-GLUE-00200] [javax.enterprise.web] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148113587] [levelValue: 800] Created virtual server server

[2019-05-29T16:41:53.957+0000] [] [INFO] [AS-WEB-CORE-00306] [javax.enterprise.web.core] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148113957] [levelValue: 800] Setting JAAS app name glassfish-web

[2019-05-29T16:41:53.957+0000] [] [INFO] [AS-WEB-GLUE-00201] [javax.enterprise.web] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148113957] [levelValue: 800] Virtual server server loaded default web module 

[2019-05-29T16:41:57.129+0000] [] [SEVERE] [] [javax.enterprise.system.tools.deployment.dol] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148117129] [levelValue: 1000] AS-DEPLOYMENT-00026

[2019-05-29T16:41:57.135+0000] [] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148117135] [levelValue: 1000] Exception while deploying the app [my-app]

[2019-05-29T16:41:57.135+0000] [] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148117135] [levelValue: 1000] [[
  Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: JNDI lookup failed for the resource: Name: [MyAppPU], Lookup: [jdbc/MyAppDB], Type: [javax.sql.DataSource]
    at com.sun.enterprise.deployment.util.ResourceValidator.validateJNDIRefs(ResourceValidator.java:896)

Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/MyAppDB' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: MyAppDB not found]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:496)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.sun.enterprise.deployment.util.ResourceValidator.validateJNDIRefs(ResourceValidator.java:891)
    ... 32 more
Caused by: javax.naming.NameNotFoundException: MyAppDB not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:208)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:70)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:483)
    ... 36 more
]]

[2019-05-29T16:41:57.284+0000] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148117284] [levelValue: 800] Deployed 1 archive(s)

[2019-05-29T16:42:01.387+0000] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148121387] [levelValue: 800] [[

Payara Micro URLs:

]]

[2019-05-29T16:42:01.388+0000] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559148121388] [levelValue: 800] Payara Micro  5.191 #badassmicrofish (build 94) ready in 14,400 (ms)

更新

我添加了一个预引导脚本来设置系统标记部署。如rel = nofollow noreferrer> payara / Payara / issues / 3449

I added a preboot script to set a system flag deployment.resource.validation as mentioned at payara/Payara/issues/3449

preboot.asadmin:

preboot.asadmin:

create-system-properties deployment.resource.validation=false

启动日志记录显示命令已执行成功但从未添加资源:

The start-up logging shows that the command executed successfully, but the resources are never added:

[2019-06-03T15:04:58.993+0000] [] [INFO] [] [fish.payara.boot.runtime.BootCommand] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1559574298993] [levelValue: 800] Boot Command create-system-properties returned with result SUCCESS : PlainTextActionReporterSUCCESSNo monitoring data to report.

我还改为使用 payara-resources.xml 具有以下DOCTYPE:

I also changed to using payara-resources.xml with the following DOCTYPE:

<!DOCTYPE resources PUBLIC "-//Payara.fish//DTD Payara Server 4 Resource Definitions//EN" "https://raw.githubusercontent.com/payara/Payara-Server-Documentation/master/schemas/payara-resources_1_6.dtd">


推荐答案

我终于成功了。首先,我要部署的应用程序是带有打包的EJB模块的WAR,因此 persistence.xml 需要打包在 WAR / WEB-INF / lib 。结构如下:

I finally got this working. First, the application I'm deploying is a WAR with packaged EJB modules, so the persistence.xml needs to be packaged in a jar within WAR/WEB-INF/lib. Here is the structure:

WAR/WEB-INF/lib/ejb1.jar
WAR/WEB-INF/lib/ejb2.jar
WAR/WEB-INF/lib/persistence.jar
WAR/WEB-INF/lib/persistence.jar/META-INF/persistence.xml
WAR/WEB-INF/payara-resources.xml

重要的是要注意 payara-resources.xml 使用环境变量。建议将我的定义放在 WAR / WEB-INF / web.xml 中,但我更喜欢从使用resources.xml获得的控制,但是我不喜欢确保 ENV 变量交换有效。

It's important to note that the resource definition in payara-resources.xml uses environment variables. It was suggested that I place my definitions in WAR/WEB-INF/web.xml, but I prefer the control I get from using resources.xml, and I'm not sure ENV variables swapping works.

WAR / WEB-INF / payara-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Payara.fish//DTD Payara Server 4 Resource Definitions//EN" "https://raw.githubusercontent.com/payara/Payara-Server-Documentation/master/schemas/payara-resources_1_6.dtd">
<resources>
    <jdbc-resource pool-name="MyAppDB" jndi-name="java:app/jdbc/MyApp" enabled="true" ></jdbc-resource>

    <jdbc-connection-pool datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerDataSource" 
                          name="MyAppDB" 
                          res-type="javax.sql.DataSource">
      <property name="User" value="${ENV=MY_APP_DATABASE_USER}"></property>
      <property name="Password" value="${ENV=MY_APP_DATABASE_PASS}"></property>
      <property name="DatabaseName" value="${ENV=MY_APP_DATABASE_NAME}"></property>
      <property name="ServerName" value="${ENV=MY_APP_DATABASE_SERVER}"></property>
      <property name="PortNumber" value="1433"></property>
    </jdbc-connection-pool>  
</resources>

这是持久性:

WAR / WEB-INF / lib / persistence.jar / META-INF / persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
  <persistence-unit name="MyAppPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>java:app/jdbc/MyApp</jta-data-source>
    <!-- other stuff //-->
  </persistence-unit>
</persistence>

使用jar作为 persistence.xml 是可以在项目(服务)之间共享持久性定义。不幸的是,Micro请求JNDI名称的 java:app / 前缀,因为部署到Full Server的项目没有使用它(我没有使用<$进行测试c $ c> java:app / 在完整服务器部署中)。无论如何,上面的作品。

One of the benefits of using a jar for persistence.xml is that the persistence definition can be shared across projects (services). Unfortunately, Micro requests the java:app/ prefix to the JNDI name, where as project deployed to a Full Server doesn't use that (I haven't tested using java:app/ in a Full Server deployment, yet). Anyway, the above works.

这篇关于PayaraMicro没有在WAR的glassfish-resources.xml中添加JDBC详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆