简体   繁体   English

构建 jar 文件但 (dockerize) Spring Boot 应用程序启动

[英]Build jar file but (dockerize) Spring Boot Application starts

I want to build a jar file from my Spring Boot Application, in order to build a docker image.我想从我的 Spring Boot 应用程序构建一个 jar 文件,以构建一个 docker 镜像。

I select "package" resp.我选择“包”resp。 run maven with "package" as commandline.使用“包”作为命令行运行 maven。 Instead it runs the whole Spring Boot Application.相反,它运行整个 Spring Boot 应用程序。 At the end it fails because it refers to a dockerize mysql db.最后它失败了,因为它指的是 dockerize mysql db。 Since the db and the Spring Boot application are in different networks, it fails of course:由于 db 和 Spring Boot 应用程序在不同的网络中,它当然失败了:

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:我的application.properties文件:

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 :我的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我的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.我不明白为什么必须首先启动 Spring Boot 应用程序。 Can't maven create a jar file without starting the Spring Boot App? maven不启动Spring Boot App就不能创建jar文件吗?

I think its happening because you have some TestCases, even if you have added none, default Spring boot will have a empty Test File.我认为这是因为您有一些 TestCases,即使您没有添加,默认的 Spring boot 也会有一个空的测试文件。

Try to skip testcases while mvn package trigger尝试在mvn package触发时跳过测试用例

mvn package -DskipTests

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM