JAVA SpringBoot:在 Docker 中,liquibase 插件运行时出现错误并且不执行更改日志

Posted

技术标签:

【中文标题】JAVA SpringBoot:在 Docker 中,liquibase 插件运行时出现错误并且不执行更改日志【英文标题】:JAVA SpringBoot : when inside a Docker the liquibase plugin runs with errors and does not execute changelogs 【发布时间】:2020-12-20 05:59:35 【问题描述】:

我知道已经问过同样的问题,但我无法询问用户是否解决了问题,而且他的问题还不够完整,无法从其他用户那里获得帮助

WARN Cannot create filesystem for url jar:file:/app.jar!/BOOT-INF/classes!/: null java.nio.file.FileSystemNotFoundException: null

因此,我将在此处提供更多信息以尝试解决此问题:

我有一个 springboot 应用程序在 docker 上运行了几个月,我正在向这个应用程序添加 spring liquibase 插件,这个插件在我的本地计算机上正常工作但是当我在 docker 中运行它时我有以下错误(并且不执行 liquibase 更改日志):

下面是一个错误示例,但其中大约 400 个出现在日志中,类路径中的每个 jar 一个...下面的示例是这些错误中的最后一个,它指的是“jakarta.validation-api- 2.0.2.jar”,如第一行所示,但问题不在于这个特定的 jar,我在运行此应用程序的 docker 中实现 Liquibase 时一定有问题。


2020-09-01 00:11:11.219  WARN 1 --- [           main] liquibase.resource                       : Cannot create filesystem for url jar:file:/opt/target/hov2.jar!/BOOT-INF/lib/jakarta.validation-api-2.0.2.jar!/: null
java.nio.file.FileSystemNotFoundException: null
    at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(Unknown Source) ~[jdk.zipfs:na]
    at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(Unknown Source) ~[jdk.zipfs:na]
    at java.base/java.nio.file.Path.of(Unknown Source) ~[na:na]
    at java.base/java.nio.file.Paths.get(Unknown Source) ~[na:na]
    at liquibase.resource.ClassLoaderResourceAccessor.loadRootPaths(ClassLoaderResourceAccessor.java:63) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.resource.ClassLoaderResourceAccessor.init(ClassLoaderResourceAccessor.java:47) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.resource.ClassLoaderResourceAccessor.openStreams(ClassLoaderResourceAccessor.java:94) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.resource.CompositeResourceAccessor.openStreams(CompositeResourceAccessor.java:33) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.parser.core.xml.LiquibaseEntityResolver.resolveEntity(LiquibaseEntityResolver.java:40) ~[liquibase-core-4.0.0.jar!/:na]
    at java.xml/com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper.resolveEntity(Unknown Source) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) ~[na:na]
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[na:na]
    at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:91) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:223) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Liquibase$1.run(Liquibase.java:194) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Scope.lambda$child$0(Scope.java:159) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Scope.child(Scope.java:170) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Scope.child(Scope.java:158) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Scope.child(Scope.java:137) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Liquibase.runInScope(Liquibase.java:1790) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Liquibase.update(Liquibase.java:183) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.Liquibase.update(Liquibase.java:179) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:322) ~[liquibase-core-4.0.0.jar!/:na]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:270) ~[liquibase-core-4.0.0.jar!/:na]
    at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46) ~[spring-boot-autoconfigure-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:255) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:229) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5128) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source) ~[na:na]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
    ......
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.1.RELEASE.jar!/:2.3.1.RELEASE]
    at com.vyv.hov2.MinimalApplication.main(MinimalApplication.java:74) ~[classes!/:2]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[hov2.jar:2]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) ~[hov2.jar:2]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[hov2.jar:2]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[hov2.jar:2]

pom.xml 查看使用的版本:

<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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>xxxx</groupId>
    <artifactId>xxxx</artifactId>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <spring-boot.version>2.3.1.RELEASE</spring-boot.version>
        <hibernate.version>5.4.12.Final</hibernate.version>
        <liquibase-core.version>4.0.0</liquibase-core.version>
        <liquibase-maven-plugin.version>4.0.0</liquibase-maven-plugin.version>
        <liquibase-hibernate5.version>4.0.0</liquibase-hibernate5.version>
        <validation-api.version>2.0.1.Final</validation-api.version>
        <javassist.version>3.27.0-GA</javassist.version>
        <jaxb-api.version>2.4.0-b180830.0359</jaxb-api.version>
        <maven.build.timestamp.format>yyyy-MM-dd'T'HH.mm.ss</maven.build.timestamp.format>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- JPA + Postgresql -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>4.0.0</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>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>$validation-api.version</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <activatedProperties>dev</activatedProperties>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <activatedProperties>prod</activatedProperties>
            </properties>
        </profile>
    </profiles>
    <build>
        <plugins>
                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>$liquibase-maven-plugin.version</version>
                    <configuration>
                        <propertyFile>src/main/resources/liquibase-$activatedProperties.properties</propertyFile>
                        <outputChangeLogFile>src/main/resources/db/db.changelog-$activatedProperties.xml</outputChangeLogFile>
                        <changeLogFile>src/main/resources/db/db.changelog-$activatedProperties.xml</changeLogFile>
                        <diffChangeLogFile>src/main/resources/db/changelog/$activatedProperties/$maven.build.timestamp_changelog.xml</diffChangeLogFile>
                        <diffTypes>tables,columns,indexes,foreignkeys,primarykeys,uniqueconstraints</diffTypes>
                        <logging>info</logging>
                    </configuration>
                    <!-- Liquibase dependencies-->
                    <dependencies>
                        <dependency>
                            <groupId>org.liquibase</groupId>
                            <artifactId>liquibase-core</artifactId>
                            <version>$liquibase-core.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.liquibase.ext</groupId>
                            <artifactId>liquibase-hibernate5</artifactId>
                            <version>$liquibase-hibernate5.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-data-jpa</artifactId>
                            <version>$spring-boot.version</version>
                        </dependency>
                        <dependency>
                            <groupId>javax.validation</groupId>
                            <artifactId>validation-api</artifactId>
                            <version>$validation-api.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.javassist</groupId>
                            <artifactId>javassist</artifactId>
                            <version>$javassist.version</version>
                        </dependency>
                        <dependency>
                            <groupId>javax.xml.bind</groupId>
                            <artifactId>jaxb-api</artifactId>
                            <version>$jaxb-api.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.postgresql</groupId>
                            <artifactId>postgresql</artifactId>
                            <version>$postgresql.version</version>
                        </dependency>
                    </dependencies>
                </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>$spring-boot.version</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.12.0</version>
                <executions>
                    <execution>
                        <id>pmd-scan</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

liquibase-dev.properties:

url=jdbc:postgresql://$DB_HOST:$DB_PORT/$DB_NAME
username=xxxx
password=xxxx
driver=org.postgresql.Driver
#### Reference database properties
referenceUrl=hibernate:spring:com.vyv.hov2.domain?dialect=org.hibernate.dialect.PostgreSQLDialect
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceDefaultSchemaName=db
verbose=true

码头文件:

FROM maven:3.6.3-openjdk-11-slim as BUILD
WORKDIR /usr/src/app
COPY checkstyle.xml .
COPY checkstyle-supressions.xml .
COPY licenseheader.txt .
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src src
COPY .git ./.git/
RUN mvn -B -e -C -T 1C package  -Dmaven.test.skip=true


FROM openjdk:11.0.8-jre
EXPOSE 8081
COPY --from=BUILD /usr/src/app/target/*.jar /opt/target/hov2.jar
WORKDIR /opt/target
ENV TZ="America/Bogota"
ENV SPRING_PROFILES_ACTIVE="dev"
ENV APP_HTTP_THREADS="4"
ENV DB_MAX_POOL="4"
ENV DB_CONN_TIMEOUT="20000"
ENV DB_HOST="192.168.x.x"
ENV DB_PORT="xxxx"
ENV DB_NAME="yyyy"
ENV DB_USER="zzzz"
ENV DB_PASSWORD="zzzz"
RUN apt-get -y update && apt-get -y install apt-utils tzdata && apt-get -y clean
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar hov2.jar $JAR_OPTS

docker build 的结果给出:

D:\GitLab\hov2-springboot>docker build -t xxxx/hov:spring .
Sending build context to Docker daemon  69.29MB
Step 1/27 : FROM maven:3.6.3-openjdk-11-slim as BUILD
 ---> 5f736c971204
Step 2/27 : MAINTAINER xxxxx
 ---> Using cache
 ---> 58e7bae3a780
Step 3/27 : WORKDIR /usr/src/app
 ---> Using cache
 ---> b790cb47ac8e
Step 4/27 : COPY checkstyle-GlobalRemises.xml .
 ---> Using cache
 ---> 105a291c538e
Step 5/27 : COPY checkstyle-supressions.xml .
 ---> Using cache
 ---> 59f933795b44
Step 6/27 : COPY licenseheader.txt .
 ---> Using cache
 ---> 227d608636c9
Step 7/27 : COPY pom.xml .
 ---> Using cache
 ---> 3de8cfcf50ce
Step 8/27 : RUN mvn -B dependency:resolve dependency:resolve-plugins
 ---> Using cache
 ---> 4505edb08bc0
Step 9/27 : COPY src src
 ---> 5580f85e37b0
Step 10/27 : COPY .git ./.git/
 ---> 9ffa9fdd1d6b
Step 11/27 : RUN mvn -B -e -C -T 1C package  -Dmaven.test.skip=true
 ---> Running in db75577e3260
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 8
[INFO]
[INFO] --------------------< com.vyv.hov2:HOV2-SpringBoot >--------------------
[INFO] Building HerramientaOperativa 2
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ HOV2-SpringBoot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 994 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ HOV2-SpringBoot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 536 source files to /usr/src/app/target/classes
[INFO] --- jacoco-maven-plugin:0.8.4:report (report) @ HOV2-SpringBoot ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ HOV2-SpringBoot ---
[INFO] Building jar: /usr/src/app/target/HOV2-SpringBoot-2.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.3.1.RELEASE:repackage (repackage) @ HOV2-SpringBoot ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- spring-boot-maven-plugin:2.3.1.RELEASE:repackage (default) @ HOV2-SpringBoot ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20.784 s (Wall Clock)
[INFO] Finished at: 2020-09-01T05:07:54Z
[INFO] ------------------------------------------------------------------------
Removing intermediate container db75577e3260
 ---> 419a981baa13
Step 12/27 : FROM openjdk:11.0.8-jre
 ---> 9cbf6d4bac44
Step 13/27 : EXPOSE 8081
 ---> Using cache
 ---> 48eec46f876c
Step 14/27 : COPY --from=BUILD /usr/src/app/target/*.jar /opt/target/hov2.jar
 ---> 13d80ab4c8a9
Step 15/27 : WORKDIR /opt/target
 ---> Running in f87f4fa28359
Removing intermediate container f87f4fa28359
 ---> c00e6df5a4a3
Step 16/27 : ENV TZ="America/Bogota"
 ---> Running in 09d317dc80d3
Removing intermediate container 09d317dc80d3
 ---> 57e64896eb41
Step 17/27 : ENV SPRING_PROFILES_ACTIVE=""
Step 26/27 : RUN apt-get -y update && apt-get -y install apt-utils tzdata && apt-get -y clean
 ---> Running in 180a8975bfa8
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages [224 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [7868 B]
Fetched 8378 kB in 4s (2176 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
tzdata is already the newest version (2020a-0+deb10u1).
tzdata set to manually installed.
The following NEW packages will be installed:
  apt-utils libapt-inst2.0
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 624 kB of archives.
After this operation, 1650 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 libapt-inst2.0 amd64 1.8.2.1 [203 kB]
Get:2 http://deb.debian.org/debian buster/main amd64 apt-utils amd64 1.8.2.1 [421 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 624 kB in 1s (796 kB/s)
Selecting previously unselected package libapt-inst2.0:amd64.
(Reading database ... 7867 files and directories currently installed.)
Preparing to unpack .../libapt-inst2.0_1.8.2.1_amd64.deb ...
Unpacking libapt-inst2.0:amd64 (1.8.2.1) ...
Selecting previously unselected package apt-utils.
Preparing to unpack .../apt-utils_1.8.2.1_amd64.deb ...
Unpacking apt-utils (1.8.2.1) ...
Setting up libapt-inst2.0:amd64 (1.8.2.1) ...
Setting up apt-utils (1.8.2.1) ...
Processing triggers for libc-bin (2.28-10) ...
Removing intermediate container 180a8975bfa8
 ---> 6b67dd296d7e
Step 27/27 : ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar hov2.jar $JAR_OPTS
 ---> Running in d8740b5c5e53
Removing intermediate container d8740b5c5e53
 ---> ca68efe70b02
Successfully built ca68efe70b02
Successfully tagged xxxx/hov:spring
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It
 is recommended to double check and reset permissions for sensitive files and directories.

liquibase 部分的 dev.properties

# *************   liquibase for DEV
spring.liquibase.enabled=true
spring.liquibase.url=jdbc:postgresql://$DB_HOST:$DB_PORT/$DB_NAME
# Change log configuration path.
spring.liquibase.change-Log=classpath:/db/db.changelog-dev.xml
#spring.liquibase.contexts= # Comma-separated list of runtime contexts to use.
# Name of table to use for tracking concurrent Liquibase usage.
spring.liquibase.database-change-log-lock-table=DATABASECHANGELOGLOCK
# Name of table to use for tracking change history.
spring.liquibase.database-change-log-table=DATABASECHANGELOG
#spring.liquibase.default-schema=
# Whether to first drop the database schema.
spring.liquibase.drop-first=false
spring.liquibase.password=xxxx
spring.liquibase.user=xxxx

启动 docker 时(使用开发上下文)一切正常,直到 liquibase 插件启动,然后出现数千个错误行(类路径中存在的每个 Jar 一个错误),然后在这些错误之后应用程序启动正常,唯一的问题是 liquibase changlogs 当然没有执行,因此插件失去了大部分实用程序......

这里是没有错误的启动日志,以防有用的东西在这里:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2020-09-01 00:11:02.477  INFO 1 --- [           main] com.vyv.hov2.MinimalApplication          : Starting MinimalApplication v2 on c795be63b326 with PID 1 (/opt/target/hov2.jar started by root in /opt/target)
2020-09-01 00:11:02.484  INFO 1 --- [           main] com.vyv.hov2.MinimalApplication          : The following profiles are active: dev
2020-09-01 00:11:05.413  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-09-01 00:11:06.555  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1120ms. Found 92 JPA repository interfaces.
2020-09-01 00:11:08.286  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@2f40a43' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-09-01 00:11:08.298  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-09-01 00:11:08.993  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (https)
2020-09-01 00:11:09.013  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-09-01 00:11:09.013  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.36]
2020-09-01 00:11:09.136  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-09-01 00:11:09.137  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6415 ms
2020-09-01 00:11:09.465  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-09-01 00:11:09.722  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-09-01 00:11:10.384  INFO 1 --- [           main] liquibase.lockservice                    : Successfully acquired change log lock
2020-09-01 00:11:10.435  WARN 1 --- [           main] liquibase.integration                    : Cannot create filesystem for url jar:file:/opt/target/hov2.jar!/BOOT-INF/classes!/: null

java.nio.file.FileSystemNotFoundException: null

Here come the hundreds of error ... then the rest is normal again:

2020-09-01 00:11:11.871  INFO 1 --- [           main] liquibase.changelog                      : Reading from public.databasechangelog
2020-09-01 00:11:11.925  INFO 1 --- [           main] liquibase.lockservice                    : Successfully released change log lock
2020-09-01 00:11:11.935  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-09-01 00:11:11.946  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-09-01 00:11:12.096  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Starting...
2020-09-01 00:11:12.134  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Start completed.
2020-09-01 00:11:12.312  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-09-01 00:11:12.467  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.12.Final

我做错了什么? 我的一个想法是 pom.xml 中指示的 db-changelog-dev.xml 的路径在我的计算机和 docker 中不会相同,但此路径是相对于 src 文件夹的,所以我不不知道怎么改。。。 我有这个想法是因为在 springboot 启动的日志中我们可以看到 liquibase 获得了数据库 changlog 表上的锁,但是在任何地方都看不到 liquibase 对 db-changelog-dev.xml 的打开,并且错误与文件系统错误,所以对我来说似乎很重要,但我没有设法解决它。 感谢任何可以让我走上正轨的想法。

感谢@shrom,第一个引发异常的 liquibase 方法具有以下 javadocs:

    /**
     * The classloader search logic in @link #list(String, String, boolean, boolean, boolean) does not handle jar files well.
     * This method is called by that method to populate @link #rootPaths with additional paths to search.
     */

我喜欢“不能很好地处理 jar 文件”!那是轻描淡写。 看起来那些警告不是我遇到的 liquibase 插件不执行数据库更新问题的根源。我必须在其他地方遇到另一个问题,因为根据上面引用的其他帖子,其他用户有这些错误,但数据库已更新。而且他们只是警告不是真正的错误......我会继续挖掘。

【问题讨论】:

您是否在本地计算机上针对本地数据库运行容器?可能无法从您的容器访问 db。 不,我在本地机器上运行相同的确切上下文,具有相同的数据库服务器......并且可以从容器访问数据库,因为该应用程序从不运行 changlogs 的 liquibase 插件运行良好 Java 是一个生态系统,在调试和自省方面具有极好的可能性。我的建议:使用它!如果我是你,我会在启用远程调试的情况下启动 docker 容器,附加 IDE 的调试器并在异常附近的某处设置断点。它甚至说这些行,所以我将从 ClassLoaderResourceAccessor.java:63 开始。是的,您将调试 liquibase,这并不可怕。看看它拥有的对象。您可能会认出您的一些配置。一小步。按照它的路径,看看变量。 99% 的人肯定会知道问题出在哪里。 它拥有的对象是一个字符串,它试图“映射”到文件系统位置,但这个字符串是我们在日志中看到的那个“/​​opt/target/hov2.jar!/ BOOT-INF/lib/jakarta.validation-api-2.0.2.jar!/: null",当然它找不到它......我会尝试其他版本的liquibase......这个尝试是在for遍历构建的所有罐子的循环... :( 【参考方案1】:

找到原因:

为了摆脱这些错误,我不得不彻底改变我的 pom.xml。 我删除了属性部分中所有在引用的 springboot 父级(特别是 spring-boot-dependencies-2.3.1.RELEASE.pom )中已经有值的硬编码版本号,而是使用了这个文件的属性。结果,一些结果版本较低,但我相信比我自己更多的 spring 来指示正确的插件兼容版本。生成的 POM 如下:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <java.version>11</java.version>
        <liquibase-hibernate5.version>3.10.1</liquibase-hibernate5.version>
        <javassist.version>3.27.0-GA</javassist.version>
        <maven.build.timestamp.format>yyyy-MM-dd'T'HH.mm.ss</maven.build.timestamp.format>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
    </dependency>
    ...
<build>
        <plugins>
                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>$liquibase.version</version>
                    <configuration>
                        <propertyFile>src/main/resources/liquibase-$activatedProperties.properties</propertyFile>
                        <outputChangeLogFile>src/main/resources/db/db.changelog-$activatedProperties.xml</outputChangeLogFile>
                        <changeLogFile>src/main/resources/db/db.changelog-$activatedProperties.xml</changeLogFile>
                        <diffChangeLogFile>src/main/resources/db/changelog/$activatedProperties/$maven.build.timestamp_changelog.xml</diffChangeLogFile>
                        <diffTypes>tables,columns,indexes,foreignkeys,primarykeys,uniqueconstraints</diffTypes>
                        <!-- diffTypes=tables, views, columns, indexes, foreignkeys, primarykeys, uniqueconstraints, data -->
                        <logging>info</logging>
                    </configuration>
                    <!-- Liquibase dependencies-->
                    <dependencies>
                        <dependency>
                            <groupId>org.liquibase</groupId>
                            <artifactId>liquibase-core</artifactId>
                            <version>$liquibase.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.liquibase.ext</groupId>
                            <artifactId>liquibase-hibernate5</artifactId>
                            <version>$liquibase-hibernate5.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-data-jpa</artifactId>
                            <version>$spring-boot.version</version>
                        </dependency>
                        <dependency>
                            <groupId>javax.validation</groupId>
                            <artifactId>validation-api</artifactId>
                            <version>$javax-validation.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.javassist</groupId>
                            <artifactId>javassist</artifactId>
                            <version>$javassist.version</version>
                        </dependency>
                        <dependency>
                            <groupId>javax.xml.bind</groupId>
                            <artifactId>jaxb-api</artifactId>
                            <version>$javax-jaxb.version</version>
                        </dependency>
                        <dependency>
                            <groupId>org.postgresql</groupId>
                            <artifactId>postgresql</artifactId>
                            <version>$postgresql.version</version>
                        </dependency>
                    </dependencies>
                </plugin>
            <plugin>
...

在插件部分的这个 pom 中,您将看到版本号属性,这些值是从 SpringBoot pom 继承的,不再在我自己的 pom 中硬编码。

现在在 Docker 中运行良好! 如果您有同样的问题并且我的回答不允许您解决它,请发表评论,我将添加我也所做的其他更改,目前,我怀疑有任何影响。

【讨论】:

以上是关于JAVA SpringBoot:在 Docker 中,liquibase 插件运行时出现错误并且不执行更改日志的主要内容,如果未能解决你的问题,请参考以下文章

JAVA SpringBoot:在 Docker 中,liquibase 插件运行时出现错误并且不执行更改日志

『中级篇』docker之java容器运行外置springboot-jar(番外篇)(79)

SpringBoot+Docker项目打包(jar)和部署

springboot之docker启动参数传递

java版spring cloud+spring boot 社交电子商务平台 (二十四)springboot整合docker

将命令行参数传递给在 Docker 中运行的 Java 应用程序(Spring Boot)