繁体   English   中英

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

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

我想从我的 Spring Boot 应用程序构建一个 jar 文件,以构建一个 docker 镜像。

我选择“包”resp。 使用“包”作为命令行运行 maven。 相反,它运行整个 Spring Boot 应用程序。 最后它失败了,因为它指的是 dockerize mysql db。 由于 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

我的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

我的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"]

我的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...]

我不明白为什么必须首先启动 Spring Boot 应用程序。 maven不启动Spring Boot App就不能创建jar文件吗?

我认为这是因为您有一些 TestCases,即使您没有添加,默认的 Spring boot 也会有一个空的测试文件。

尝试在mvn package触发时跳过测试用例

mvn package -DskipTests

暂无
暂无

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

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