У меня есть приложение Java EE 11, развернутое и работающее на JBoss WildFly 16.0.0. Финал в контейнере Docker.
ИД ИЗОБРАЖЕНИЯ КОМАНДЫ КОНТЕЙНЕРА
СОЗДАННЫЕ ПОРТЫ СОСТОЯНИЯ
ИМЕНА 867d2b0c179bgostophandle: latest "/ opt / jboss / wildfly /…" 4 секунды назад вверх 3 секунды 0.0.0.0:32826->8080/tcp
Elegant_shtern
У меня также работает экземпляр MongoDBв докерном контейнере.
ИД КОНТЕЙНЕРА КОМАНДА ИЗОБРАЖЕНИЯ
ИМЯ СОЗДАННЫХ ПОРТОВ СОСТОЯНИЯ 1c064a161638 mongo "docker-entrypoint.s…" 2 минуты назад Up 2 минуты 27017 / tcp goStopHandle
Thisмой «persistence.xml», который я использую для подключения к экземпляру «localhost» MongoDB:
<persistence-unit name="goStopHandleMongoDBPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<!-- <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/> -->
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.3"/>
<!-- <property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.8"/> -->
<property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.10"/>
<!-- <property name="hibernate.transaction.jta.platform" value="JBossTS"/> -->
<!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAS"/> -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.datastore.mongodb.MongoDBDialect"/>
<property name="hibernate.ogm.datastore.database" value="goStopHandleDB"/>
<property name="hibernate.ogm.datastore.host" value="127.0.0.1:27017"/>
</properties>
</persistence-unit>
Я запустил:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' aea9f245ff90
и получил IP-адресконтейнер MongoDB:
172.17.0.2
Я изменил файл persistence.xml для использования:
<property name="hibernate.ogm.datastore.host" value="172.17.0.2:27017"/>
Когда я запускаю свой контейнер WildFly, я получаю:
[0m[0m19:39:18,823 INFO [org.mongodb.driver.cluster] (cluster-ClusterId{value='5ca50be6c9e77c00671d9ec5', description='null'}-gostophandle:27017) Exception in monitor thread while connecting to server gostophandle:27017: com.mongodb.MongoSocketException: gostophandle: Name or service not known
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.UnknownHostException: gostophandle: Name or service not known
at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
... 5 more
[0m[0m19:39:19,327 INFO [org.mongodb.driver.cluster] (cluster-ClusterId{value='5ca50be6c9e77c00671d9ec5', description='null'}-gostophandle:27017) Exception in monitor thread while connecting to server gostophandle:27017: com.mongodb.MongoSocketException: gostophandle
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.UnknownHostException: gostophandle
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
... 5 more
[0m[0m19:39:28,841 INFO [org.mongodb.driver.cluster] (cluster-ClusterId{value='5ca50be6c9e77c00671d9ec5', description='null'}-gostophandle:27017) Exception in monitor thread while connecting to server gostophandle:27017: com.mongodb.MongoSocketException: gostophandle: Name or service not known
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.UnknownHostException: gostophandle: Name or service not known
at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
... 5 more
[0m[0m19:39:29,344 INFO [org.mongodb.driver.cluster] (cluster-ClusterId{value='5ca50be6c9e77c00671d9ec5', description='null'}-gostophandle:27017) Exception in monitor thread while connecting to server gostophandle:27017: com.mongodb.MongoSocketException: gostophandle
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.UnknownHostException: gostophandle
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
at org.hibernate.ogm.mongodb:5.4@5.4.1.Final//com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
... 5 more
Любойпредложения по настройке файла persistence.xml?