I'm creating a simple web app for class that will use a MongoDB Atlas database, but I can't make any network connection. I have a user account set up, have 0.0.0.0/0 whitelisted, and believe I have the code setup correctly for a connection. When I try running to test the app, I get java.net.SocketException: Network is unreachable all over the place. With the console log below, does anyone see an obvious error? I have tried the ports to make sure they are open and haven't found an error, not sure why the connection totally fails.
application.properties:
# MongoDB Atlas - Connection
spring.data.mongodb.database=bookclub
spring.data.mongodb.uri=mongodb+srv://bookclub_user:<pwd>#cluster0.ne3yt.mongodb.net/<database>?retryWrites=true&w=majority
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
</parent>
<groupId>com.bookclub</groupId>
<artifactId>bookclub</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>bookclub</name>
<description>CIS 530 Bookclub Project</description>
<properties>
<java.version>16</java.version>
</properties>
<dependencies>
<!-- Form validation fields -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.5.5</version>
</dependency>
<!-- Thymeleaf template engine -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- MongoDB Driver -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
NEW console output:
:: Spring Boot :: (v2.5.4)
2021-10-04 04:52:24.130 INFO 36899 --- [ restartedMain] com.bookclub.BookclubApplication : Starting BookclubApplication using Java 16.0.2 on C02YPFQ9LVCG with PID 36899 (/Users/abecthold/Courses/cis-530/bookclub/target/classes started by abecthold in /Users/abecthold/Courses/cis-530/bookclub)
2021-10-04 04:52:24.132 INFO 36899 --- [ restartedMain] com.bookclub.BookclubApplication : No active profile set, falling back to default profiles: default
2021-10-04 04:52:24.169 INFO 36899 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-10-04 04:52:24.169 INFO 36899 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-10-04 04:52:24.574 INFO 36899 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2021-10-04 04:52:24.582 INFO 36899 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6 ms. Found 0 MongoDB repository interfaces.
2021-10-04 04:52:24.914 INFO 36899 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-10-04 04:52:24.921 INFO 36899 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-10-04 04:52:24.921 INFO 36899 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.52]
2021-10-04 04:52:24.968 INFO 36899 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-10-04 04:52:24.968 INFO 36899 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 798 ms
2021-10-04 04:52:25.059 INFO 36899 --- [ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[cluster0.ne3yt.mongodb.net:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-10-04 04:52:25.127 INFO 36899 --- [ngodb.net:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server cluster0.ne3yt.mongodb.net:27017
com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net: nodename nor servname provided, or not known
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:143) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.2.3.jar:na]
at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: java.net.UnknownHostException: cluster0.ne3yt.mongodb.net: nodename nor servname provided, or not known
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:932) ~[na:na]
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1517) ~[na:na]
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:851) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1507) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1366) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1300) ~[na:na]
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203) ~[mongodb-driver-core-4.2.3.jar:na]
... 6 common frames omitted
2021-10-04 04:52:25.185 INFO 36899 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2021-10-04 04:52:25.394 INFO 36899 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2021-10-04 04:52:25.485 INFO 36899 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-10-04 04:52:25.493 INFO 36899 --- [ restartedMain] com.bookclub.BookclubApplication : Started BookclubApplication in 1.608 seconds (JVM running for 2.09)
2021-10-04 04:52:35.129 INFO 36899 --- [ngodb.net:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server cluster0.ne3yt.mongodb.net:27017
com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:143) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.2.3.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.2.3.jar:na]
at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: java.net.UnknownHostException: cluster0.ne3yt.mongodb.net
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:800) ~[na:na]
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:886) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1507) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1366) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1300) ~[na:na]
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203) ~[mongodb-driver-core-4.2.3.jar:na]
... 6 common frames omitted
New errors on web view when trying to connect through the app:
There was an unexpected error (type=Internal Server Error, status=500).
Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=cluster0.ne3yt.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net}, caused by {java.net.UnknownHostException: cluster0.ne3yt.mongodb.net}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=cluster0.ne3yt.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net}, caused by {java.net.UnknownHostException: cluster0.ne3yt.mongodb.net}}]
org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=cluster0.ne3yt.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net}, caused by {java.net.UnknownHostException: cluster0.ne3yt.mongodb.net}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=cluster0.ne3yt.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net}, caused by {java.net.UnknownHostException: cluster0.ne3yt.mongodb.net}}
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=cluster0.ne3yt.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: cluster0.ne3yt.mongodb.net}, caused by {java.net.UnknownHostException: cluster0.ne3yt.mongodb.net}}]
I've posted a relatively similar question in the past here. I am attempting to configure my environment to work with VirtualBox so I can use Linux related tools to manage the servers. Currently, I am attempting to connect my Spring Boot web application to my Ubuntu MySQL server on my VirtualBox machine.
Problem
When attempting to connect to my MySQL server with my Spring Boot application, I received this error message:
2020-06-06 08:16:02.390 INFO 2936 --- [ restartedMain] c.c.mvcblog.SpringMvcBlogApplication : Starting SpringMvcBlogApplication on DESKTOP-AS2P0GJ with PID 2936 (C:\Users\rocke\IdeaProjects\mvc-blog\target\classes started by rocke in C:\Users\rocke\IdeaProjects\mvc-blog)
2020-06-06 08:16:02.396 INFO 2936 --- [ restartedMain] c.c.mvcblog.SpringMvcBlogApplication : No active profile set, falling back to default profiles: default
2020-06-06 08:16:02.480 INFO 2936 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-06-06 08:16:02.480 INFO 2936 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-06-06 08:16:04.076 INFO 2936 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-06-06 08:16:04.215 INFO 2936 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 127ms. Found 2 JPA repository interfaces.
2020-06-06 08:16:05.913 INFO 2936 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-06-06 08:16:05.940 INFO 2936 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-06-06 08:16:05.940 INFO 2936 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-06-06 08:16:06.141 INFO 2936 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-06-06 08:16:06.141 INFO 2936 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3660 ms
2020-06-06 08:16:06.474 INFO 2936 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-06-06 08:16:06.572 INFO 2936 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-06-06 08:16:06.672 WARN 2936 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-06-06 08:16:06.788 INFO 2936 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.15.Final
2020-06-06 08:16:07.055 INFO 2936 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-06-06 08:16:07.205 INFO 2936 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-06-06 08:16:10.357 ERROR 2936 --- [ task-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: 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.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.5.jar:na]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1214) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1245) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
A handful of resources I found online related to this topic were dealing with invalid login attempts, invalid MySQL queries, or invalid dialects.
Debugging Information
I am able to ping the virtual machine when actively running. I ended up installing MySQL directly onto my local machine (Windows 10) and attempted to connect directly that way. After squashing a few bugs related to me using the wrong dialect, I was able to connect directly to my MySQL database on my local machine. However, switching back at that point to my Ubuntu hosted MySQL server still resulted in the same error message. I have also verified that the MySQL service is running. Lastly, I've also tried adding the 3306 port for MySQL.
Code
You can find my current repository here. I'll show the most important pieces of my project here.
application.properties
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.0.101:3306/blog_db
spring.datasource.username=root
spring.datasource.password=mIThl
# Configure Hibernate DDL mode: create / update
spring.jpa.properties.hibernate.hbm2ddl.auto = create
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Maven Pom Dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Additionally, my Spring Boot Parent version is 2.3.0.RELEASE.
I greatly appreciate any help given! I'm eager to improve my development process by incorporating VirtualBox VM's and am hoping to be able to find a resolution for this issue. Thank you!
I'm running JHipster 5.8.1 on a Manjaro Linux Intel i7 (x64) and I'm facing a problem with my Jhipster application.
That is, I created a project, imported my jdl entities correctly and configured the application in application-dev.yml file, but when I run mvn spring-boot:run JHipster prints some log lines and program gets stuck in one of them and hangs for a long time at line
2019-02-04 19:30:01.448 DEBUG 13716 --- [ restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration : Started Swagger in 13ms
until is throws a SQLException for it couldn't acquire lock
For instance, I've tried to inspect backend generated code, change spring.profiles.active from dev to:
spring:
profiles:
active: dev, fast
Here is the complete log:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< br.ufpa.labes.spm:spm >------------------------
[INFO] Building Spm 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.0.8.RELEASE:run (default-cli) > test-compile # spm >>>
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:copy-resources (default-resources) # spm ---
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) # spm ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 342 resources
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (enforce-versions) # spm ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.2:prepare-agent (pre-unit-tests) # spm ---
[INFO] argLine set to -javaagent:/home/arjuna/.m2/repository/org/jacoco/org.jacoco.agent/0.8.2/org.jacoco.agent-0.8.2-runtime.jar=destfile=/home/arjuna/Documentos/Algoritmos/JHipster/spm/target/test-results/coverage/jacoco/jacoco.exec -Djava.security.egd=file:/dev/./urandom -Xmx256m
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # spm ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 868 source files to /home/arjuna/Documentos/Algoritmos/JHipster/spm/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) # spm ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # spm ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.0.8.RELEASE:run (default-cli) < test-compile # spm <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.8.RELEASE:run (default-cli) # spm ---
[INFO] Attaching agents: []
The Class-Path manifest attribute in /home/arjuna/.m2/repository/org/liquibase/liquibase-core/3.5.5/liquibase-core-3.5.5.jar referenced one or more files thatdo not exist: file:/home/arjuna/.m2/repository/org/liquibase/liquibase-core/3.5.5/lib/snakeyaml-1.13.jar
██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗
██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
██║ ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝
██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗
╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
:: JHipster 🤓 :: Running Spring Boot 2.0.8.RELEASE ::
:: https://www.jhipster.tech ::
2019-02-05 23:32:04.146 DEBUG 15146 --- [ restartedMain] b.u.labes.spm.config.AsyncConfiguration : Creating Async Task Executor
2019-02-05 23:32:06.359 DEBUG 15146 --- [ restartedMain] c.ehcache.core.Ehcache-usersByLogin : Initialize successful.
//Database tables initializing
c.e.c.E.u.labes.spm.domain.UserPlugin : Initialize successful.
2019-02-05 23:32:08.407 DEBUG 15146 --- [ restartedMain] b.u.l.spm.config.LiquibaseConfiguration : Configuring Liquibase
2019-02-05 23:32:09.603 ERROR 15146 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : Hikari - Exception during pool initialization.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2197)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at
// ...stacktrace methods catches
at
org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:301)
... 147 common frames omitted
2019-02-05 23:32:15.950 DEBUG 15146 --- [ restartedMain] br.ufpa.labes.spm.config.WebConfigurer : Registering CORS filter
2019-02-05 23:32:16.067 INFO 15146 --- [ restartedMain] br.ufpa.labes.spm.config.WebConfigurer : Web application configuration, using profiles: dev
2019-02-05 23:32:16.068 INFO 15146 --- [ restartedMain] br.ufpa.labes.spm.config.WebConfigurer : Web application fully configured
2019-02-05 23:32:16.489 DEBUG 15146 --- [ restartedMain] b.u.l.spm.security.jwt.TokenProvider : Using a Base64-encoded JWT secret key
2019-02-05 23:32:31.019 DEBUG 15146 --- [ restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration : Starting Swagger
2019-02-05 23:32:31.034 DEBUG 15146 --- [ restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration : Started Swagger in 15
Possible cause seems to be mysql is refusing connections for an unknown reason.
I expect Jhipster to start application and show links to access application from working both backend and frontend.
Thanks for helping!
Check this in the log, OutOfMemoryError.
I think, probably is for your memory, maybe u need more memory, or u can config for use more (check the following links) or in other sever, maybe cloud.
Links, to configure more memory, check these answers:
How to deal with “java.lang.OutOfMemoryError: Java heap space” error?
Error Java heap space
I hope you help, regards.
I am trying to build spring boot MongoDB project provided at https://spring.io/guides/gs/accessing-data-mongodb/ which is using spring-boot-starter-parent 2.0.0.RELEASE,
and getting
stack trace:
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:62) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114) ~[mongodb-driver-core-3.6.3.jar:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
Caused by: java.net.SocketException: Socket operation on non-socket (Error setting socket option)
at java.net.PlainSocketImpl.socketSetOption0(Native Method) ~[na:1.8.0_151]
at java.net.PlainSocketImpl.socketSetOption(PlainSocketImpl.java:88) ~[na:1.8.0_151]
at java.net.AbstractPlainSocketImpl.setOption(AbstractPlainSocketImpl.java:275) ~[na:1.8.0_151]
at java.net.Socket.setTcpNoDelay(Socket.java:980) ~[na:1.8.0_151]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:36) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.SocketStream.open(SocketStream.java:57) ~[mongodb-driver-core-3.6.3.jar:na]
... 3 common frames omitted
When I changed spring-boot-starter-parent version to 1.5.9.RELEASE or 1.5.10.RELEASE, the same code is working fine. So is there any problem with version 2.0.0.RELEASE when using spring data mongo.
System details:
mongod version: 3.4.13
openjdk version "1.8.0_151"
I had to install and start mongodb first for spring-boot-starter-parent 2.0.x
assuming you are using MacOS
# to install mongodb
➜ ~ brew install mongodb
# To have launchd start mongodb now and restart at login
➜ ~ brew services start mongodb
after that everything worked as expected:
2018-04-05 22:13:43.189 INFO 26777 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2018-04-05 22:13:43.229 INFO 26777 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:1}] to localhost:27017
2018-04-05 22:13:43.234 INFO 26777 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 3]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=3049505}
2018-04-05 22:13:43.352 INFO 26777 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2018-04-05 22:13:43.469 INFO 26777 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:2}] to localhost:27017
2018-04-05 22:13:43.471 INFO 26777 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 3]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1552605}
I downloaded the example from Spring Data MongoDB 2.0 - Reactive examples.
I'm failing to understand how to make it work.
I set up a cluster in cloud.mongodb.com and they supply me with:
If I am using driver 3.6 or later:
mongodb+srv://stavalfi:<PASSWORD>#cluster0-9yjy8.mongodb.net/test
Else, if I am using driver 3.4 or earlier:
mongodb://stavalfi:<PASSWORD>#cluster0-shard-00-00-
9yjy8.mongodb.net:27017,cluster0-shard-00-01-
9yjy8.mongodb.net:27017,cluster0-shard-00-02-
9yjy8.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-
0&authSource=admin
I don't know what is the version of the driver which spring uses so I chose the first one:
#SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
#EnableReactiveMongoRepositories
#AutoConfigureAfter(EmbeddedMongoAutoConfiguration.class)
#RequiredArgsConstructor
class ApplicationConfiguration extends AbstractReactiveMongoConfiguration {
private final Environment environment;
public static void main(String args[]) throws InterruptedException {
ConfigurableApplicationContext run = SpringApplication.run(ApplicationConfiguration.class);
run.getBean(ReactiveMongoTemplate.class)
.save("something to push")
.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("success"));
Thread.sleep(1000000);
}
#Bean
public LoggingEventListener mongoEventListener() {
return new LoggingEventListener();
}
#Override
#Bean
#DependsOn("embeddedMongoServer")
public MongoClient reactiveMongoClient() {
return MongoClients.create(String.format("mongodb+srv://stavalfi:<MyAccountPassword!>#cluster0-9yjy8.mongodb.net/test"));
// int port = environment.getProperty("local.mongo.port", Integer.class);
// return MongoClients.create(String.format("mongodb://localhost:%d", port));
}
#Override
protected String getDatabaseName() {
return "reactive";
}
}
I'm sure I'm not doing anything as Spring Data MongoDB project expected me to do.
The Exception I get while creating the Bean: MongoClient
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reactiveMongoClient' defined in example.springdata.mongodb.people.ApplicationConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.reactivestreams.client.MongoClient]: Factory method 'reactiveMongoClient' threw exception; nested exception is java.lang.UnsupportedOperationException: No SSL support in java.nio.channels.AsynchronousSocketChannel. For SSL support use com.mongodb.connection.netty.NettyStreamFactoryFactory
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1250) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at example.springdata.mongodb.people.ApplicationConfiguration.main(ApplicationConfiguration.java:53) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.reactivestreams.client.MongoClient]: Factory method 'reactiveMongoClient' threw exception; nested exception is java.lang.UnsupportedOperationException: No SSL support in java.nio.channels.AsynchronousSocketChannel. For SSL support use com.mongodb.connection.netty.NettyStreamFactoryFactory
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
... 17 common frames omitted
Caused by: java.lang.UnsupportedOperationException: No SSL support in java.nio.channels.AsynchronousSocketChannel. For SSL support use com.mongodb.connection.netty.NettyStreamFactoryFactory
at com.mongodb.connection.AsynchronousSocketChannelStreamFactory.<init>(AsynchronousSocketChannelStreamFactory.java:58) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.AsynchronousSocketChannelStreamFactory.<init>(AsynchronousSocketChannelStreamFactory.java:43) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.async.client.MongoClients.getStreamFactory(MongoClients.java:237) ~[mongodb-driver-async-3.6.3.jar:na]
at com.mongodb.async.client.MongoClients.create(MongoClients.java:181) ~[mongodb-driver-async-3.6.3.jar:na]
at com.mongodb.async.client.MongoClients.create(MongoClients.java:172) ~[mongodb-driver-async-3.6.3.jar:na]
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:90) ~[mongodb-driver-reactivestreams-1.7.1.jar:na]
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:75) ~[mongodb-driver-reactivestreams-1.7.1.jar:na]
at example.springdata.mongodb.people.ApplicationConfiguration.reactiveMongoClient(ApplicationConfiguration.java:70) [classes/:na]
at example.springdata.mongodb.people.ApplicationConfiguration$$EnhancerBySpringCGLIB$$6152c801.CGLIB$reactiveMongoClient$1(<generated>) ~[classes/:na]
at example.springdata.mongodb.people.ApplicationConfiguration$$EnhancerBySpringCGLIB$$6152c801$$FastClassBySpringCGLIB$$4cbf5891.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at example.springdata.mongodb.people.ApplicationConfiguration$$EnhancerBySpringCGLIB$$6152c801.reactiveMongoClient(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
... 18 common frames omitted
How can I fix this?
Played around with this some. You can find details from Mongo Java Driver tutorials.
First I tried using the DSL approach, which would be neat to have all the setup as code:
application.yml
mongo:
user: training_mongo
password: <my_password>
hosts:
- training-abcde.mongodb.net
database: training
MongoProperties.java
#ConfigurationProperties("mongo")
#Component
public class MongoProperties {
private String user;
private String password;
private List<String> hosts;
private String database;
ApplicationConfiguration.java
#Configuration
#EnableWebFlux
#EnableReactiveMongoRepositories
public class ApplicationConfig extends AbstractReactiveMongoConfiguration {
[...]
#Override
public MongoClient reactiveMongoClient() {
return create(MongoClientSettings.builder()
.clusterSettings(ClusterSettings.builder()
.hosts(mongoProperties.getHosts()
.stream()
.map(ServerAddress::new)
.collect(toList()))
.build())
.streamFactoryFactory(NettyStreamFactory::new)
.sslSettings(SslSettings.builder()
.enabled(true)
.build())
.credential(MongoCredential.createCredential(
mongoProperties.getUser(),
mongoProperties.getDatabase(),
mongoProperties.getPassword().toCharArray()))
.build());
}
#Override
protected String getDatabaseName() {
return DB_NAME;
}
This however crashes, because Netty fires a DNS lookup through the Java stack and that fails:
[DEBUG] [TestEventLogger] 2018-08-06 17:22:17.147 INFO 16148 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
[DEBUG] [TestEventLogger]
[DEBUG] [TestEventLogger] com.mongodb.MongoSocketOpenException: Exception opening socket
[ ... stacktrace ...]
[DEBUG] [TestEventLogger]
[DEBUG] [TestEventLogger] 2018-08-06 17:22:17.278 INFO 16148 --- [ Test worker] org.mongodb.driver.cluster : Cluster created with settings {hosts=[training-abcde.mongodb.net:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[DEBUG] [TestEventLogger] 2018-08-06 17:22:17.279 INFO 16148 --- [ Test worker] org.mongodb.driver.cluster : Adding discovered server training-abcde.mongodb.net:27017 to client view of cluster
[DEBUG] [TestEventLogger] 2018-08-06 17:22:17.975 INFO 16148 --- [ Test worker] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[TestEventLogger] 2018-08-06 17:22:18.006 INFO 16148 --- [ngodb.net:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server training-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger]
[DEBUG] [TestEventLogger] com.mongodb.MongoSocketOpenException: Exception opening socket
[... stacktrace ...]
[DEBUG] [TestEventLogger] Caused by: java.net.UnknownHostException: No such host is known (training-abcde.mongodb.net)
[DEBUG] [TestEventLogger] at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:925) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1505) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:844) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1495) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1354) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1288) ~[na:na]
[DEBUG] [TestEventLogger] at java.base/java.net.InetAddress.getByName(InetAddress.java:1238) ~[na:na]
[DEBUG] [TestEventLogger] at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:146) ~[netty-common-4.1.25.Final.jar:4.1.25.Final]
[DEBUG] [TestEventLogger] at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:143) ~[netty-common-4.1.25.Final.jar:4.1.25.Final]
[DEBUG] [TestEventLogger] at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
But doing things less elegantly via the connection URL seem to work:
ApplicationConfiguration.java:
#Configuration
#EnableWebFlux
#EnableReactiveMongoRepositories
public class ApplicationConfig extends AbstractReactiveMongoConfiguration {
private static final String CONNECTION_URL = "mongodb+srv://%s:%s#%s/%s?retryWrites=true&streamType=netty&ssl=true";
[...]
#Override
public MongoClient reactiveMongoClient() {
return MongoClients.create(getMongoConnectionUrl());
}
#Override
protected String getDatabaseName() {
return DB_NAME;
}
private String getMongoConnectionUrl() {
String connectionUrl = String.format(CONNECTION_URL, mongoProperties.getUser(), mongoProperties.getPassword(),
mongoProperties.getHosts().get(0), mongoProperties.getDatabase());
return connectionUrl;
}
[DEBUG] [TestEventLogger] 2018-08-06 18:25:37.132 INFO 4252 --- [ Test worker] org.mongodb.driver.cluster : Cluster created with settings {hosts=[training-shard-00-00-abcde.mongodb.net:27017, training-shard-00-01-abcde.mongodb.net:27017, training-shard-00-02-abcde.mongodb.net:27017], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='training-shard-0'}
[DEBUG] [TestEventLogger] 2018-08-06 18:25:37.132 INFO 4252 --- [ Test worker] org.mongodb.driver.cluster : Adding discovered server training-shard-00-00-abcde.mongodb.net:27017 to client view of cluster
[DEBUG] [TestEventLogger] 2018-08-06 18:25:37.135 INFO 4252 --- [ Test worker] org.mongodb.driver.cluster : Adding discovered server training-shard-00-01-abcde.mongodb.net:27017 to client view of cluster
[DEBUG] [TestEventLogger] 2018-08-06 18:25:37.139 INFO 4252 --- [ Test worker] org.mongodb.driver.cluster : Adding discovered server training-shard-00-02-abcde.mongodb.net:27017 to client view of cluster
[DEBUG] [TestEventLogger] 2018-08-06 18:25:37.831 INFO 4252 --- [ Test worker] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.450 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:161155}] to training-shard-00-00-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.468 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=training-shard-00-00-abcde.mongodb.net:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 6]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=16287599, setName='training-shard-0', canonicalAddress=training-shard-00-00-abcde.mongodb.net:27017, hosts=[training-shard-00-00-abcde.mongodb.net:27017, training-shard-00-02-abcde.mongodb.net:27017, training-shard-00-01-abcde.mongodb.net:27017], passives=[], arbiters=[], primary='training-shard-00-00-abcde.mongodb.net:27017', tagSet=TagSet{[]}, electionId=7fffffff0000000000000008, setVersion=1, lastWriteDate=Mon Aug 06 18:25:37 SRET 2018, lastUpdateTimeNanos=70366873909383}
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.473 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.cluster : Setting max election id to 7fffffff0000000000000008 from replica set primary training-shard-00-00-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.474 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.cluster : Setting max set version to 1 from replica set primary training-shard-00-00-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.475 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.cluster : Discovered replica set primary training-shard-00-00-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.479 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:4, serverValue:71172}] to training-shard-00-02-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.496 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=training-shard-00-02-abcde.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 6]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=16406907, setName='training-shard-0', canonicalAddress=training-shard-00-02-abcde.mongodb.net:27017, hosts=[training-shard-00-00-abcde.mongodb.net:27017, training-shard-00-02-abcde.mongodb.net:27017, training-shard-00-01-abcde.mongodb.net:27017], passives=[], arbiters=[], primary='training-shard-00-00-abcde.mongodb.net:27017', tagSet=TagSet{[]}, electionId=null, setVersion=1, lastWriteDate=Mon Aug 06 18:25:37 SRET 2018, lastUpdateTimeNanos=70366902099001}
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.497 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:224436}] to training-shard-00-01-abcde.mongodb.net:27017
[DEBUG] [TestEventLogger] 2018-08-06 18:25:38.512 INFO 4252 --- [ngodb.net:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=training-shard-00-01-abcde.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 6]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=14614118, setName='training-shard-0', canonicalAddress=training-shard-00-01-abcde.mongodb.net:27017, hosts=[training-shard-00-00-abcde.mongodb.net:27017, training-shard-00-02-abcde.mongodb.net:27017, training-shard-00-01-abcde.mongodb.net:27017], passives=[], arbiters=[], primary='training-shard-00-00-abcde.mongodb.net:27017', tagSet=TagSet{[]}, electionId=null, setVersion=1, lastWriteDate=Mon Aug 06 18:25:37 SRET 2018, lastUpdateTimeNanos=70366918148773}
I think it haven't SSL Certificate or may be the wrong or dummy SSL Certificate are there. That's why it's display No SSL support in java.nio.channels.AsynchronousSocketChannel
From the docs:
If you are using the reactive driver, Netty is required for SSL. The auto-configuration configures this factory automatically if Netty is available and the factory to use hasn’t been customized already.
Make sure that you have netty on the classpath (either selected modules or netty-all).