您的位置:首页技术文章
文章详情页

oracle - Docker中发布java web项目Could not get JDBC Connection

浏览:95日期:2024-03-22 10:12:31

问题描述

项目是(spring+mybatis+oracle)docker是安装在虚拟机下面的,jdbc连接的数据库是安装另外一台linux的物理机上面,本机测试能通过,但是到虚拟机里的docker环境下就报这个错误,是什么原因?报错信息如下:Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-00604: 递归 SQL 级别 1 出现错误ORA-01882: 未找到时区)

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The Network Adapter could not establish the connection)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)

问题解答

回答1:

Docker容器如果需要链接其他主机的话,运行时需要使用'--net=host'选项,表示容器与主机共享网络。

sudo docker run --net=host 回答2:

试着将虚拟机设置NAT网络模式。设置好之后虚拟机的网络行为就像宿主机一样,访问外网和宿主机所在的局域网。

标签: java
相关文章: