我有一个Sping Boot 应用程序,我想与Oracle数据库连接,使用Oracle Database Free Container / Docker images.映像进行容器化。
此外,我使用docker compose来配置数据库部署,并使用 Sping Boot Docker Compose 在应用程序启动时运行部署。
但是,由于以下错误,我的应用程序无法连接到数据库:
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=V0w3NC+xSxaZYliy+XojdA==)
at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:892) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:697) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
字符串
Oracle容器看起来不错:
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_FREE)))
2023-12-18T19:40:23.357410157Z Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
2023-12-18T19:40:23.357437163Z
2023-12-18T19:40:23.357462169Z Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_FREE)))
2023-12-18T19:40:23.377109429Z STATUS of the LISTENER
2023-12-18T19:40:23.377387489Z ------------------------
2023-12-18T19:40:23.377432499Z Alias LISTENER
2023-12-18T19:40:23.377468507Z Version TNSLSNR for Linux: Version 23.0.0.0.0 - Production
2023-12-18T19:40:23.377499514Z Start Date 18-DEC-2023 19:40:23
2023-12-18T19:40:23.377528520Z Uptime 0 days 0 hr. 0 min. 0 sec
2023-12-18T19:40:23.377556526Z Trace Level off
2023-12-18T19:40:23.381577398Z Security ON: Local OS Authentication
2023-12-18T19:40:23.381807448Z SNMP OFF
2023-12-18T19:40:23.381845456Z Default Service FREE
2023-12-18T19:40:23.381875462Z Listener Parameter File /opt/oracle/product/23c/dbhomeFree/network/admin/listener.ora
2023-12-18T19:40:23.381903469Z Listener Log File /opt/oracle/diag/tnslsnr/f8cd793dc1d4/listener/alert/log.xml
2023-12-18T19:40:23.381930474Z Listening Endpoints Summary...
2023-12-18T19:40:23.383162742Z (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_FREE)))
2023-12-18T19:40:23.383223755Z (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
2023-12-18T19:40:23.383255762Z The listener supports no services
2023-12-18T19:40:23.385380222Z The command completed successfully
2023-12-18T19:40:33.630788572Z ORACLE instance started.
型
此外,Docker配置和Docker合成设置与gvenzl/oracle-free:latest
镜像设置instructions内联
Spring应用程序配置:
spring:
liquibase:
enabled: false
datasource:
url: jdbc:oracle:thin:@localhost:1521/FREEPDB1
username: PERSONS_DB
password: Lider0ne
型
Docker compose设置
services:
oracle:
image: 'gvenzl/oracle-free:latest'
environment:
- 'ORACLE_RANDOM_PASSWORD=true'
- 'APP_USER=PERSONS_DB'
- 'APP_USER_PASSWORD=Lider0ne'
ports:
- 1521:1521
型
最后,我得到一个类似的错误连接到数据库使用IntelliJ数据库工具窗口。
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=gZO5dOjYRGKjaOL469MGIw==).
型
的数据
注意:我在Apple M芯片上运行Docker
根据Oracle Database Free文档,这应该没有问题,我按照它的指示使用colima和--arch -x86_64
选项运行容器。容器成功启动,如上所述。
你有没有遇到过同样的问题?如果有,我该如何解决
1条答案
按热度按时间webghufk1#
Docker compose为您创建了一个桥接网络
docker network ls
,其中服务发现正在发生。localhost是Spring App的本地主机(并且您没有在Spring App容器中运行Oracle数据库)
字符串
因此,您可以通过服务名称
'oracle'
访问数据库(:1521是默认值,可以省略)型
祝你好运!