Bud*_*tne 4 glassfish payara mysql-8.0
我有一个 Maven JSF/JPA Web 应用程序,它连接到使用 Netbeans 12 开发的 MySQL 5.x。该应用程序运行良好,直到我将 MySQL 版本从 5.x 更新到 8.x。自该更新以来,我无法配置数据库以连接到 JSF 应用程序。与 MySQL 8.x 的连接在 Netbeans 中正常工作,但在部署应用程序时不起作用。
当前配置包括 EclipseLink 2.7.7、MySQL 8.0.23 和 GlassFish 5(5.0.1) / Payara 5(5.2021.1)。无法成功连接到 MySQL。我也无法在 GlassFish 和 Payara 管理控制台的 JDBS 连接池内建立连接。有人可以指导我找到 MySQL 版本 8 链接到 Payara 或 GlassFish 的来源吗?
Payara管理控制台中显示的错误如下。
An error has occurred Ping Connection Pool failed for pooConnection.
Connection could not be allocated because: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Please check the server.log for more details.
Run Code Online (Sandbox Code Playgroud)
日志文件包含以下内容。
[javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service] [tid: _ThreadID=161 _ThreadName=admin-thread-pool::admin-listener(3)] [timeMillis: 1613549343463] [levelValue: 900] [[
RAR8054: Exception while creating an unpooled [test] connection for pool [ pooConnection ], Connection could not be allocated because: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.]]
[2021-02-17T13:39:03.472+0530] [Payara 5.2021.1] [SEVERE] [] [org.glassfish.admingui] [tid: _ThreadID=139 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1613549343472] [levelValue: 1000] [[
RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=pooConnection}']]
Run Code Online (Sandbox Code Playgroud)
为了连接到 Payara Server,我发现唯一有效的方法是直接在域管理控制台中创建连接池。
现在看起来可能很长,但完成后它将成为第二天性:
从https://dev.mysql.com/downloads/connector/j/下载 MySQL8 Java Connector 并解压到任意文件夹:
它将解压为以下内容: mysql-connector-java-8.0.23 2/mysql-connector-java-8.0.23.jar
1) 确保 Payara 服务器已启动并正在运行:
cd PATH_TO_PAYARA/bin
Run Code Online (Sandbox Code Playgroud)
2)启动/重新启动
./asadmin start-domain
Run Code Online (Sandbox Code Playgroud)
注意:这将默认启动domain1
3)安装MySQL8连接器
./asadmin add-library PATH_TO_MYSQL_CONNECTOR.jar
Run Code Online (Sandbox Code Playgroud)
4) (必填) 重启Payara
./asadmin restart-domain
Run Code Online (Sandbox Code Playgroud)
5) 访问管理控制台:http://localhost:4848/common/index.jsf
6) 在侧边栏中导航至“JDBC”->“JDBC 连接池”菜单
7)从那里,单击“新建”以添加新的连接池
你想要多少就可以有多少。因此,如果您以前尝试过,您可以将泳池保留在那里。
8) 在:新建 JDBC 连接池(第 1 步,共 2 步)
Pool Name: MySQL8Pool (or whatever you want)
Resource Type: javax.sql.DataSource
Database Driver Vendor: MySQL8
Run Code Online (Sandbox Code Playgroud)
点击下一步”
9)向下滚动到“附加属性”
选择全部并“删除属性”
10) 添加 6 个属性,其键/值如下:
DatabaseName YOUR_DB_NAME
User YOUR_DB_USER
Password YOUR_DB_PASSWORD
ServerName localhost
PortNumber 3306
UseSSL false
Run Code Online (Sandbox Code Playgroud)
点击“保存”
11) 在侧边栏中导航至“JDBC”->“JDBC 资源”菜单
12) 从那里,单击“新建”以添加新的 JDBC 资源
并填写:
JNDI Name: jdbc/MySQL8App
PoolName: MySQL8Pool
Run Code Online (Sandbox Code Playgroud)
点击“保存”
从现在开始,我假设您正在使用 Maven。
13) 在 pom.xml 中确保您 的标签中有 Eclipse Persistence:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.asm</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.jpql</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
14) 创建一个持久化单元
在 persistence.xml 文件中:
<persistence-unit name="mysql8PU" transaction-type="JTA">
<jta-data-source>jdbc/MySQL8App</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<!--properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create OR create OR complete remove this line"/-->
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
请注意,在jta-data-source中,它指向jdbc/MySQL8App,从现在开始,它可以在代码中的任何位置使用,以便在构建 Payara 后我们可以注入它。
持久服务.java
cd PATH_TO_PAYARA/bin
Run Code Online (Sandbox Code Playgroud)
现在重建并重新运行您的项目,一切都应该没问题!
| 归档时间: |
|
| 查看次数: |
4350 次 |
| 最近记录: |