I want to build a jar file from my Spring Boot Application, in order to build a docker image.
I select "package" resp. run maven with "package" as commandline. Instead it runs the whole Spring Boot Application. At the end it fails because it refers to a dockerize mysql db. Since the db and the Spring Boot application are in different networks, it fails of course:
2020-03-11 01:37:11.655 ERROR 6128 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 5 times. Giving up.
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) ~[na:1.8.0_171]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_171]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_171]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_171]
...
Caused by: java.net.UnknownHostException: shortenedurlmysqldb
My application.properties
file:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://shortenedurlmysqldb/bootdb2?createDatabaseIfNotExist=true&autoReconnect=true&maxReconnects=5&allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=newuser
spring.datasource.password=password
spring.datasource.platform=mysql
spring.datasource.initialization-mode=always
My Dockerfile
:
From openjdk:8
copy ./target/jugtours-0.0.1-SNAPSHOT.jar jugtours-0.0.1-SNAPSHOT.jar
CMD ["java","-jar","jugtours-0.0.1-SNAPSHOT.jar"]
My application.yml
spring:
profiles:
active: spring.profiles.active@
security:
oauth2:
client:
registration:
okta:
client-id: [...secret...]
client-secret: [...secret...]
scope: openid, email, profile
provider:
okta:
issuer-uri: [...secret...]
I don't understand why the Spring Boot Application has to be started to begin with. Can't maven create a jar file without starting the Spring Boot App?
I think its happening because you have some TestCases, even if you have added none, default Spring boot will have a empty Test File.
Try to skip testcases while mvn package
trigger
mvn package -DskipTests
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.