I try to use docker-compose to containerize with starting MySQL server container first, and then start a Springboot Container to connect with the MySQL container.
But the Connection is fail(See full version in the terminal log below
web_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
How should I make changes to start my MySQL container first, then link it the Springboot Server to MySQL?
My terminal log
$ docker-compose up
Creating network "backend_default" with the default driver
Creating backend_db_1 ... done
Creating backend_web_1 ... done
Attaching to backend_db_1, backend_web_1
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
web_1 | Trying to connect to MySQL at db:3306...
db_1 | 2020-03-15 05:59:09+00:00 [Note] [Entrypoint]: Initializing database files
web_1 | /wrapper.sh: connect: Connection refused
web_1 | /wrapper.sh: line 2: /dev/tcp/db/3306: Connection refused
db_1 | 2020-03-15T05:59:09.686844Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2020-03-15T05:59:09.686961Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 43
db_1 | 2020-03-15T05:59:12.938749Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db_1 | 2020-03-15 05:59:16+00:00 [Note] [Entrypoint]: Database files initialized
db_1 | 2020-03-15 05:59:16+00:00 [Note] [Entrypoint]: Starting temporary server
db_1 | 2020-03-15T05:59:17.100779Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2020-03-15T05:59:17.100921Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 93
db_1 | 2020-03-15T05:59:17.688885Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2020-03-15T05:59:17.692200Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-03-15T05:59:17.730154Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
db_1 | 2020-03-15 05:59:17+00:00 [Note] [Entrypoint]: Temporary server started.
db_1 | 2020-03-15T05:59:17.802956Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
db_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
web_1 | /wrapper.sh: connect: Connection refused
web_1 | /wrapper.sh: line 2: /dev/tcp/db/3306: Connection refused
web_1 | Trying to connect to MySQL at db:3306...
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Creating database dog_of_the_dow_app
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Creating user shihao
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Giving user shihao access to schema dog_of_the_dow_app
db_1 |
db_1 | 2020-03-15 05:59:24+00:00 [Note] [Entrypoint]: Stopping temporary server
db_1 | 2020-03-15T05:59:24.460353Z 14 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
db_1 | 2020-03-15T05:59:25.812000Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
db_1 | 2020-03-15 05:59:26+00:00 [Note] [Entrypoint]: Temporary server stopped
db_1 |
db_1 | 2020-03-15 05:59:26+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db_1 |
db_1 | 2020-03-15T05:59:26.755391Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2020-03-15T05:59:26.755538Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
db_1 | 2020-03-15T05:59:27.241304Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2020-03-15T05:59:27.245423Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-03-15T05:59:27.270535Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
db_1 | 2020-03-15T05:59:27.417150Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
web_1 | >> connected to MySQL database! <<
web_1 |
web_1 | . ____ _ __ _ _
web_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
web_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
web_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
web_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
web_1 | =========|_|==============|___/=/_/_/_/
web_1 | :: Spring Boot :: (v2.2.4.RELEASE)
web_1 |
web_1 | 2020-03-15 05:59:32.794 INFO 8 --- [ main] c.s.a.w.d.DogOfTheDowAppApplication : Starting DogOfTheDowAppApplication v0.0.1-SNAPSHOT on 754a319ebef1 with PID 8 (/app.jar started by root in /)
web_1 | 2020-03-15 05:59:32.811 INFO 8 --- [ main] c.s.a.w.d.DogOfTheDowAppApplication : The following profiles are active: containers
web_1 | 2020-03-15 05:59:34.732 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
web_1 | 2020-03-15 05:59:34.886 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 131ms. Found 2 JPA repository interfaces.
web_1 | 2020-03-15 05:59:35.721 INFO 8 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
web_1 | 2020-03-15 05:59:36.338 INFO 8 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
web_1 | 2020-03-15 05:59:36.375 INFO 8 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
web_1 | 2020-03-15 05:59:36.376 INFO 8 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
web_1 | 2020-03-15 05:59:36.528 INFO 8 --- [ main] o.a.c.c.C.[.[.[/mobile-app-ws] : Initializing Spring embedded WebApplicationContext
web_1 | 2020-03-15 05:59:36.529 INFO 8 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3531 ms
web_1 | 2020-03-15 05:59:37.363 INFO 8 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
web_1 | 2020-03-15 05:59:37.588 INFO 8 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final}
web_1 | 2020-03-15 05:59:38.015 INFO 8 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
web_1 | 2020-03-15 05:59:38.325 INFO 8 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
web_1 | 2020-03-15 05:59:39.613 ERROR 8 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
web_1 |
web_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
web_1 |
web_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
web_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
web_1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
...
....
web_1 |
backend_web_1 exited with code 1
My Dockerfile
Download required images
and run the wrapper.sh
wrapper.sh will keep checking if the mysql container is successfully running
if so, than start the springboot, otherwise not
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ARG SH_FILE=src/main/resources/*.sh
COPY ${SH_FILE} wrapper.sh
RUN /bin/sh -c "apk add --no-cache bash"
RUN bash -c 'touch /app.jar'
RUN bash -c 'chmod +x /wrapper.sh'
ENTRYPOINT ["/bin/bash", "/wrapper.sh"]
My wrapper.sh file
keep checking mysql server
#!/usr/bin/env bash
while ! exec 6<>/dev/tcp/${DATABASE_HOST}/${DATABASE_PORT}; do
echo "Trying to connect to MySQL at ${DATABASE_HOST}:${DATABASE_PORT}..."
sleep 10
done
echo ">> connected to MySQL database! <<"
java -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=containers -jar /app.jar
My docker-compose file
version: "2"
services:
db:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_DATABASE=example
- MYSQL_USER=shihao
- MYSQL_PASSWORD=shihao
ports:
- 3306:3306
web:
image: xli68/dog_of_the_dow:latest
depends_on:
- db
ports:
- 8080:8080
environment:
- DATABASE_HOST=db
- DATABASE_USER=shihao
- DATABASE_PASSWORD=shihao
- DATABASE_NAME=dog_of_the_dow_app
- DATABASE_PORT=3306
Related
I'm trying to send request from postman to my backend spring-boot container and I get
"could not send request" message
docker-compose.yml:
version: '3'
services:
mysqldb:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=booking
- MYSQL_USER=dhia
- MYSQL_PASSWORD=root
ports:
- 3308:3306
app:
image: app:latest
ports:
- 8091:8091
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysqldb:3306/booking
depends_on:
- mysqldb
The application started fine and 0 errors
This is my Dockerfile
FROM maven:3.8.6-openjdk-18-slim as MAVEN_BUILD
WORKDIR /build
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -Dmaven.test.skip=true
FROM openjdk:18-alpine
WORKDIR /app
ARG JAR_FILE=*.jar
COPY --from=MAVEN_BUILD /build/target/${JAR_FILE} ./app.jar
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]
bookingsystem-app-1 |
bookingsystem-app-1 | . ____ _ __ _ _
bookingsystem-app-1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
bookingsystem-app-1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
bookingsystem-app-1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
bookingsystem-app-1 | ' |____| .__|_| |_|_| |_\__, | / / / /
bookingsystem-app-1 | =========|_|==============|___/=/_/_/_/
bookingsystem-app-1 | :: Spring Boot :: (v2.7.3)
bookingsystem-app-1 |
bookingsystem-app-1 | 2022-08-21 11:10:34.994 INFO 1 --- [ main] Booking.BookingApplication : Starting BookingApplication v0.0.1-SNAPSHOT using Java 18-ea on 521f32647790 with PID 1 (/app/app.jar started by root in /app)
bookingsystem-app-1 | 2022-08-21 11:10:35.005 INFO 1 --- [ main] Booking.BookingApplication : No active profile set, falling back to 1 default profile: "default"
bookingsystem-app-1 | 2022-08-21 11:10:36.215 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
bookingsystem-app-1 | 2022-08-21 11:10:36.325 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 90 ms. Found 4 JPA repository interfaces.
bookingsystem-app-1 | 2022-08-21 11:10:37.470 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (http)
bookingsystem-app-1 | 2022-08-21 11:10:37.499 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
bookingsystem-app-1 | 2022-08-21 11:10:37.499 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
bookingsystem-app-1 | 2022-08-21 11:10:37.637 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
bookingsystem-app-1 | 2022-08-21 11:10:37.638 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2339 ms
bookingsystem-app-1 | 2022-08-21 11:10:37.753 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
bookingsystem-app-1 | 2022-08-21 11:10:38.142 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
bookingsystem-app-1 | 2022-08-21 11:10:38.342 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
bookingsystem-app-1 | 2022-08-21 11:10:38.466 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
bookingsystem-app-1 | 2022-08-21 11:10:38.792 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
bookingsystem-app-1 | 2022-08-21 11:10:38.946 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
bookingsystem-app-1 | Hibernate:
bookingsystem-app-1 |
bookingsystem-app-1 | alter table bookings
bookingsystem-app-1 | add constraint FK4xjjw8rumqxvr8c6t7xm6q8ty
bookingsystem-app-1 | foreign key (hike_id)
bookingsystem-app-1 | references hikes (id)
bookingsystem-app-1 | Hibernate:
bookingsystem-app-1 |
bookingsystem-app-1 | alter table bookings
bookingsystem-app-1 | add constraint FKg37gxkbbjvc3dp3een92kxy05
bookingsystem-app-1 | foreign key (hiker_id)
bookingsystem-app-1 | references hikers (id)
bookingsystem-app-1 | Hibernate:
bookingsystem-app-1 |
bookingsystem-app-1 | alter table hikes
bookingsystem-app-1 | add constraint FKs8qvf1tnml0ahxs407ggng3bs
bookingsystem-app-1 | foreign key (trail_id)
bookingsystem-app-1 | references trails (id)
bookingsystem-app-1 | 2022-08-21 11:10:39.988 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
bookingsystem-app-1 | 2022-08-21 11:10:40.000 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
bookingsystem-app-1 | 2022-08-21 11:10:40.542 WARN 1 --- [ main] 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
bookingsystem-app-1 | 2022-08-21 11:10:41.008 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8090 (http) with context path ''
bookingsystem-app-1 | 2022-08-21 11:10:41.019 INFO 1 --- [ main] Booking.BookingApplication : Started BookingApplication in 6.813 seconds (JVM running for 7.789)
This is my application properties file:
spring.datasource.url = jdbc:mysql://localhost:3308/booking
spring.datasource.username=root
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.password=root
createDatabaseIfNotExist=true
### JPA / HIBERNATE ###
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.generate-ddl = true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.show-sql = true
spring.jpa.properties.hibernate.format_sql = true
server.port=8090
The problem that I can't access to my controllers or send any requests I tried all the Ports and all the names ( localhost, booking, app ) and always CONNREFUSED
http://mysqldb:8080/hikes
http://mysqldb:8090/hikes
http://mysqldb:8091/hikes
http://localhost:8080/hikes
http://localhost:8090/hikes
http://localhost:8091/hikes
By the way when I run it without the container everything work fine.
Try to change these port numbers with the same port number
dockerfile -> EXPOSE 8080 -> EXPOSE 8090
docker-compose.yml -> ports: - 8091:8091 -> ports: - 8090:8090
this will work because your application using 8090 port and you using 8091 to run your application in your docker-compose, and at the same time trying to expose with 8080 port
I try to install klov-0.2.5.jar locally, my settings are as below:
Mongodb 3.2 running and listening on port 27017
klov application.properties file reside in the same folder as klov-0.2.5.jar
Have tried different ports for Klov (80, 90, 2571,1100), but all giving the same error as in description
Have tried it on mongoDB 5.0 with same result
Running it on windows 10, with application.properties settings as below:
# klov
application.name=Klov
server.host=localhost
server.port=1100
# data.mongodb
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=klov
# data.rest
spring.data.rest.basePath=/rest
spring.data.rest.default-page-size=6
# redis, session
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
spring.data.redis.repositories.enabled=false
spring.data.elasticsearch.repositories.enabled=false
spring.data.jpa.repositories.enabled=false
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.enabled=false
# use.redis.session.store=false
# spring.redis.host=localhost
# spring.redis.port=6379
# spring.redis.ssl=false
# spring.redis.database=0
# spring.session.store-type=redis
# server.session.timeout=-1
# users
server.admin.name=klovadmin
server.admin.key=$2a$10$I/5TFi6BrHChUghTZEZfCO82txzu8L5brcK0CxhS3m.V6glfj2vZe
# storage
file.storage.location=./upload/reports/
# schedulers
scheduler.jobs.enabled=false
# automatically delete older builds
# default is -1 (keep all)
# this count must be greater than 0 for this scheduler to work
# scheduled to run daily at 12:00AM
scheduler.job.builds.retain.count=-1
# mail
#spring.mail.host=
#spring.mail.port=
#spring.mail.username=
#spring.mail.password=
#spring.mail.properties.mail.smtp.ssl.enable=true
#spring.mail.properties.mail.smtp.starttls.enable=true
#spring.mail.properties.mail.smtp.starttls.required=true
#spring.mail.properties.mail.smtp.auth=true
#spring.mail.properties.mail.smtp.connectiontimeout=5000
#spring.mail.properties.mail.smtp.timeout=5000
#spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.test-connection=false
Once i try to execute jar file in my powershell i get:
poerwshell outcome
PS D:\klov\0.2.5> java -jar .\klov-0.2.5.jar
. ____ _ __ _ _ /\ / ' __ _ () __ __
_ \ \ \ \ ( ( )__ | '_ | '| | ' / ` | \ \ \ \ \/ __)| |)| | | | | || (| | ) ) ) ) ' || .__|| ||| |_, | / / / /
=========||==============|/=//// :: Spring Boot :: (v2.0.4.RELEASE)
2022-07-13 14:34:42.138 INFO 2796 --- [ main]
com.aventstack.klov.Application : Starting Application v0.2.5
on fedoruk with PID 2796 (D:\klov\0.2.5\klov-0.2.5.jar started by
mfedoruk in D:\klov\0.2.5) 2022-07-13 14:34:42.141 INFO 2796 --- [
main] com.aventstack.klov.Application : No active profile
set, falling back to default profiles: default 2022-07-13 14:34:42.215
INFO 2796 --- [ main]
ConfigServletWebServerApplicationContext : Refreshing
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#7a3d45bd:
startup date [Wed Jul 13 14:34:42 CEST 2022]; root of context
hierarchy 2022-07-13 14:34:42.984 INFO 2796 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data
modules found, entering strict repository configuration mode!
2022-07-13 14:34:43.356 ERROR 2796 --- [ main]
o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Cannot load configuration class:
com.aventstack.klov.Application
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:282)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
at com.aventstack.klov.Application.main(Application.java:61) ~[classes!/:0.2.5]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:577) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
~[klov-0.2.5.jar:0.2.5]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
~[klov-0.2.5.jar:0.2.5]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
~[klov-0.2.5.jar:0.2.5]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
~[klov-0.2.5.jar:0.2.5] Caused by:
java.lang.ExceptionInInitializerError: null
at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122)
~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
I dealt with it by:
running the newest ver of klov in docker container
then I copied the klov.jar file from container to my local path
same properties, mongoDB 5.0.9
typed java -jar -klov.jar
all started with no issues
i have a problem with docker compose when i try to run docker-compose every time i get the following error i tried many solutions but nothing helps. Please help.
I will add that I created the docker image using Cloud Native Buildpacks. I used the command:
mvn spring-boot: build-image -Dspring-boot.build-image.imageName = jakuczczubak/infrastock
and then uploaded the image to dockerhub
dockerhub: dockerhub
github: github
docker-compose.yml
services:
mysql:
image: mysql:5.7
container_name: test-mysql-docker
environment:
- MYSQL_ROOT_PASSWORD=mysqlpw
- MYSQL_USER=infrastock
- MYSQL_DATABASE=infrastock
- MYSQL_PASSWORD=infrastock123
ports:
- 33067:3306
adminer:
image: adminer
restart: always
ports:
- 8080:8080
depends_on:
- mysql
api:
image: czubakjakub/infrastock:v1.0.0
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://root:mysqlpw#test-mysql-docker:3306/infrastock?useSSL=false
- SPRING_JPA_HIBERNATE_DDL-AUTO=update
ports:
- 9090:9090
depends_on:
- mysql
application.properties
server.port=9090
spring.datasource.url=jdbc:mysql://root:mysqlpw#host.docker.internal:33067/infrastock
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
error:
- Network docker-compose_default Created 2.6s
- Container test-mysql-docker Created 0.6s
- Container docker-compose-api-1 Created 0.6s
- Container docker-compose-adminer-1 Created 0.5s
Attaching to docker-compose-adminer-1, docker-compose-api-1, test-mysql-docker
test-mysql-docker | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.
test-mysql-docker | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
test-mysql-docker | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.
test-mysql-docker | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Initializing database files
test-mysql-docker | 2022-06-22T18:55:25.410856Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
test-mysql-docker | 2022-06-22T18:55:27.139862Z 0 [Warning] InnoDB: New log files created, LSN=45790
test-mysql-docker | 2022-06-22T18:55:27.489120Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
test-mysql-docker | 2022-06-22T18:55:27.590997Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e1816692-f25c-11ec-951c-0242ac130002.
test-mysql-docker | 2022-06-22T18:55:27.604367Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
test-mysql-docker | 2022-06-22T18:55:28.037561Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
test-mysql-docker | 2022-06-22T18:55:28.037615Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
test-mysql-docker | 2022-06-22T18:55:28.038212Z 0 [Warning] CA certificate ca.pem is self signed.
test-mysql-docker | 2022-06-22T18:55:28.080678Z 1 [Warning] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
docker-compose-adminer-1 | [Wed Jun 22 18:55:29 2022] PHP 7.4.30 Development Server (http://[::]:8080) started
docker-compose-api-1 | Setting Active Processor Count to 8
docker-compose-api-1 | Calculating JVM memory based on 7046808K available memory
docker-compose-api-1 | `For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
docker-compose-api-1 | Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx6417274K -XX:MaxMetaspaceSize=117533K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 7046808K, Thread Count: 250, Loaded Class Count: 18337, Headroom: 0%)
docker-compose-api-1 | Enabling Java Native Memory Tracking
docker-compose-api-1 | Adding 127 container CA certificates to JVM truststore
docker-compose-api-1 | Spring Cloud Bindings Enabled
docker-compose-api-1 | Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx6417274K -XX:MaxMetaspaceSize=117533K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true
docker-compose-api-1 |
docker-compose-api-1 | . ____ _ __ _ _
docker-compose-api-1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
docker-compose-api-1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
docker-compose-api-1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
docker-compose-api-1 | ' |____| .__|_| |_|_| |_\__, | / / / /
docker-compose-api-1 | =========|_|==============|___/=/_/_/_/
docker-compose-api-1 | :: Spring Boot :: (v2.6.3)
docker-compose-api-1 |
docker-compose-api-1 | 2022-06-22 18:55:31.261 INFO 1 --- [ main] c.e.infrastock.InfraStockApplication : Starting InfraStockApplication v0.0.1-SNAPSHOT using Java 11.0.15.1 on a109f4fe4312 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
docker-compose-api-1 | 2022-06-22 18:55:31.270 INFO 1 --- [ main] c.e.infrastock.InfraStockApplication : No active profile set, falling back to default profiles: default
docker-compose-api-1 | 2022-06-22 18:55:32.883 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
docker-compose-api-1 | 2022-06-22 18:55:33.021 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 124 ms. Found 4 JPA repository interfaces.
docker-compose-api-1 | 2022-06-22 18:55:34.554 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http)
docker-compose-api-1 | 2022-06-22 18:55:34.583 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
docker-compose-api-1 | 2022-06-22 18:55:34.584 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
docker-compose-api-1 | 2022-06-22 18:55:34.777 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
docker-compose-api-1 | 2022-06-22 18:55:34.777 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3377 ms
docker-compose-api-1 | Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
docker-compose-api-1 | 2022-06-22 18:55:35.258 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
docker-compose-api-1 | 2022-06-22 18:55:35.367 INFO 1 --- [ main] org.hibernate.Version
: HHH000412: Hibernate ORM core version 5.6.4.Final
docker-compose-api-1 | 2022-06-22 18:55:35.583 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
docker-compose-api-1 | 2022-06-22 18:55:35.753 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
docker-compose-api-1 | 2022-06-22 18:55:35.772 WARN 1 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
docker-compose-api-1 | 2022-06-22 18:55:36.976 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
docker-compose-api-1 |
docker-compose-api-1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
docker-compose-api-1 |
docker-compose-api-1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
docker-compose-api-1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:829) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1 | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:449) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1 | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:242) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1 | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1 | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:173) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1 | at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.15.jar:5.3.15]
docker-compose-api-1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
Full stack trace: https://pastebin.com/mLPfHNbJ
Full docker-compose.yml logslogs
I have a problem with starting the Spring Boot application created by spring initializer.
mvn command stacktrace
[DEBUG] Application argument(s): --spring.application.admin.enabled=true --spring.application.admin.jmx-name=org.springframework.boot:type=Admin,name=SpringApplication
[DEBUG] Environment variable(s):
[DEBUG] Connecting to local MBeanServer at port 9001
[DEBUG] Waiting for spring application to start...
[DEBUG] MBean server at port 9001 is not up yet...
[DEBUG] Spring application is not ready yet, waiting 500ms (attempt 1)
[DEBUG] Connected to local MBeanServer at port 9001
[DEBUG] Waiting for spring application to start...
[DEBUG] Spring application is not ready yet, waiting 500ms (attempt 1)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.6)
2021-11-01 12:40:43.639 INFO 37902 --- [ main] com.example.demo1.Demo1Application : Starting Demo1Application using Java 17 on dj-legion with PID 37902 (/home/dj/Documents/demo1/target/classes started by dj in /home/dj/Documents/demo1)
2021-11-01 12:40:43.642 INFO 37902 --- [ main] com.example.demo1.Demo1Application : No active profile set, falling back to default profiles: default
[DEBUG] Spring application is not ready yet, waiting 500ms (attempt 2)
2021-11-01 12:40:44.185 INFO 37902 --- [ main] com.example.demo1.Demo1Application : Started Demo1Application in 0.947 seconds (JVM running for 1.53)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.931 s
[INFO] Finished at: 2021-11-01T12:40:44+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.6:start (default-cli) on project demo1: Could not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Connection refused to host: 127.0.0.1; nested exception is:
[ERROR] java.net.ConnectException: Connection refused
Do you have any idea how to fix this kind of error? I've tried with a lower java/maven/spring-boot versions but without success.
The solution is trivial. I forgot about web dependency and the application has been finished immediately.
Just add to your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I have set up DB2 as NoSQL storage (following https://www.ibm.com/developerworks/data/library/techarticle/dm-1306nosqlforjson4/index.html). The premise by IBM is that any application talking to MongoDB can switch to DB2 if we add the Wire Listener in between.
The layout is: Client app ----> Wire listener ----> DB2
Wire listener is started with the following command:
wlpListener -start -mongoPort 27017 -userid <user> -password <password> -dbName jsondb -logPath c:/temp/logs -host 10.0.0.6:50000
The solution works fine with a simple Python client:
from pymongo import MongoClient
client = MongoClient('10.0.0.6', 27017)
database = client['jsondb']
coll = database.mycollection
coll.insert_one({"name":"Jerry","age":5})
print(coll.find_one({"name": "Jerry"}))
However, when I use a Spring Boot application designed for MongoDB (using Spring Data JPA) I get the following exception during initialization:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.2)
2021-02-14 11:13:28.629 INFO 11820 --- [ main] c.i.a.n.generator.gen.MainGenerator : Starting MainGenerator using Java 1.8.0 on SP-NIT09160021 with PID 11820 (C:\Users\user\Documents\Workspaces\nosql-poc-db2-wirednosql\target\classes started by user in C:\Users\user\Documents\Workspaces\nosql-poc-db2-wirednosql)
2021-02-14 11:13:28.635 INFO 11820 --- [ main] c.i.a.n.generator.gen.MainGenerator : No active profile set, falling back to default profiles: default
2021-02-14 11:13:29.375 INFO 11820 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2021-02-14 11:13:29.450 INFO 11820 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 69 ms. Found 3 MongoDB repository interfaces.
2021-02-14 11:13:30.006 INFO 11820 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-02-14 11:13:30.016 INFO 11820 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-14 11:13:30.016 INFO 11820 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-14 11:13:30.132 INFO 11820 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-14 11:13:30.132 INFO 11820 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1414 ms
2021-02-14 11:13:30.304 INFO 11820 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[10.0.0.6:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-02-14 11:13:30.380 INFO 11820 --- [-10.0.0.6:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 10.0.0.6:27017
com.mongodb.MongoException: org.bson.BsonInvalidOperationException: Value expected to be of type INT32 is of unexpected type DOUBLE
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:157) ~[mongodb-driver-core-4.1.1.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.1.1.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.1.jar:na]
at java.lang.Thread.run(Thread.java:785) [na:1.8.0-internal]
Caused by: org.bson.BsonInvalidOperationException: Value expected to be of type INT32 is of unexpected type DOUBLE
at org.bson.BsonValue.throwIfInvalidType(BsonValue.java:419) ~[bson-4.1.1.jar:na]
at org.bson.BsonValue.asInt32(BsonValue.java:94) ~[bson-4.1.1.jar:na]
at org.bson.BsonDocument.getInt32(BsonDocument.java:555) ~[bson-4.1.1.jar:na]
at com.mongodb.internal.connection.DescriptionHelper.getMaxWireVersion(DescriptionHelper.java:104) ~[mongodb-driver-core-4.1.1.jar:na]
at com.mongodb.internal.connection.DescriptionHelper.createConnectionDescription(DescriptionHelper.java:63) ~[mongodb-driver-core-4.1.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:117) ~[mongodb-driver-core-4.1.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:62) ~[mongodb-driver-core-4.1.1.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:144) ~[mongodb-driver-core-4.1.1.jar:na]
... 3 common frames omitted
As if there was an incompatibility between the Mongo driver and what the Wire Listener expects.
Versions:
Host system: Windows 10
Database server: DB2/LINUXX8664 11.5.5.0 (using the Docker container from https://hub.docker.com/r/ibmcom/db2 )
IBM DB2 NoSQL WireListener 1.4.0.0 build 1.4.118
IBM DB2 NoSQL JSON 1.1.0.0 build 1.4.249
Java application (1.8 jdk), Spring Boot 2.4.2, [Mongodb.bson, mongodb-driver-core, mongodb-driver-sync] 4.1.1.
This is a bug in the Wire Listener.
The MongoDB driver expects an Int:
private static int getMinWireVersion(final BsonDocument isMasterResult) {
return isMasterResult.getInt32("minWireVersion", new BsonInt32(getDefaultMinWireVersion())).getValue();
}
private static int getMaxWireVersion(final BsonDocument isMasterResult) {
return isMasterResult.getInt32("maxWireVersion", new BsonInt32(getDefaultMaxWireVersion())).getValue();
}
But the Wire Listener is reporting a Double.
I would suggest to get latest IBM DB2 NoSQL WireListener from IBM Support that contains fix of this issue.
If you have no issue in downloading quick fix from github, you can download and use this file: https://github.com/ibmdb/db2drivers/blob/main/db2NoSQLWireListener1.4.119.zip
it contains fix of this issue. Thanks.