我有一个带有micronaut数据(postgresql)和liquibase的Micronaut 2.0应用程序。
当我在IDEA或本地jar中运行应用程序时,它工作正常。应用程序具有多个迁移,当它在docker中运行时,只有第一个成功执行,然后由于错误而失败:
app_1 | 06:40:33.937 [main] INFO liquibase.executor.jvm.JdbcExecutor -
CREATE TABLE public.marker_type (id SMALLINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(20) NOT NULL, title VARCHAR(20) NOT NULL, description VARCHAR(100), CONSTRAINT MARKER_TYPE_PKEY PRIMARY KEY (id), UNIQUE (title), UNIQUE (name))
app_1 | 06:40:33.948 [main] INFO liquibase.changelog.ChangeSet - Table marker_type created
app_1 | 06:40:33.953 [main] INFO liquibase.changelog.ChangeSet - SQL in file sql/20200715-1712-create_marker_type_table.sql executed
app_1 | 06:40:33.955 [main] INFO liquibase.changelog.ChangeSet - ChangeSet classpath:db/migrations/change-log.yml::20200715-1712-create_marker_type_table ran successfully in 18ms
app_1 | 06:40:33.956 [main] INFO liquibase.executor.jvm.JdbcExecutor - SELECT MAX(ORDEREXECUTED) FROM public.databasechangelog
app_1 | 06:40:33.961 [main] INFO l.lockservice.StandardLockService - Successfully released change log lock
app_1 | 06:40:33.963 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: null
app_1 | io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [javax.sql.DataSource] could not be loaded: null
app_1 | at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1540)
app_1 | at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:220)
app_1 | at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2768)
app_1 | at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:228)
app_1 | at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:166)
app_1 | at io.micronaut.runtime.Micronaut.start(Micronaut.java:64)
app_1 | at ru.vinguardsoft.ApplicationKt.main(Application.kt:9)
app_1 | Caused by: java.lang.NullPointerException: null
app_1 | at liquibase.util.LiquibaseUtil.getBuildInfo(LiquibaseUtil.java:45)
app_1 | at liquibase.util.LiquibaseUtil.getBuildVersion(LiquibaseUtil.java:17)
app_1 | at liquibase.sqlgenerator.core.MarkChangeSetRanGenerator.generateSql(MarkChangeSetRanGenerator.java:91)
app_1 | at liquibase.sqlgenerator.core.MarkChangeSetRanGenerator.generateSql(MarkChangeSetRanGenerator.java:25)
app_1 | at liquibase.sqlgenerator.SqlGeneratorChain.generateSql(SqlGeneratorChain.java:30)
app_1 | at liquibase.sqlgenerator.SqlGeneratorFactory.generateSql(SqlGeneratorFactory.java:222)
app_1 | at liquibase.executor.AbstractExecutor.applyVisitors(AbstractExecutor.java:25)
app_1 | at liquibase.executor.jvm.JdbcExecutor.access$600(JdbcExecutor.java:40)
app_1 | at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:384)
app_1 | at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:59)
app_1 | at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:131)
app_1 | at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:111)
app_1 | at liquibase.changelog.StandardChangeLogHistoryService.setExecType(StandardChangeLogHistoryService.java:388)
app_1 | at liquibase.database.AbstractJdbcDatabase.markChangeSetExecStatus(AbstractJdbcDatabase.java:1130)
app_1 | at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:64)
app_1 | at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83)
app_1 | at liquibase.Liquibase.update(Liquibase.java:202)
app_1 | at liquibase.Liquibase.update(Liquibase.java:179)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.performUpdate(LiquibaseMigrationRunner.java:189)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.migrate(LiquibaseMigrationRunner.java:146)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.run(LiquibaseMigrationRunner.java:109)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.lambda$null$0(LiquibaseMigrationRunner.java:91)
app_1 | at java.base/java.util.Optional.ifPresent(Optional.java:183)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.lambda$onCreated$1(LiquibaseMigrationRunner.java:91)
app_1 | at java.base/java.util.Optional.ifPresent(Optional.java:183)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.onCreated(LiquibaseMigrationRunner.java:88)
app_1 | at io.micronaut.liquibase.LiquibaseMigrationRunner.onCreated(LiquibaseMigrationRunner.java:62)
app_1 | at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1945)
app_1 | at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2635)
app_1 | at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2621)
app_1 | at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2163)
app_1 | at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1538)
app_1 | ... 6 common frames omitted
应用的第二次运行出现错误:relation marker_type already exists
如果将Micronaut降级至v1并且不更改其他代码,则应用程序在docker中运行不会出现问题。Micronaut 2有什么问题?
UPD:
application.yml
的片段:datasources:
default:
url: 'jdbc:postgresql://${DB_HOST:localhost}:5432/demo'
username: 'postgres'
password: '1234'
driverClassName: 'org.postgresql.Driver'
jpa:
default:
entity-scan:
packages: 'models'
properties:
hibernate:
hbm2ddl:
auto: none
show_sql: true
liquibase:
datasources:
default:
change-log: 'classpath:db/migrations/change-log.yml'
DB_HOST
是docker-compose中的环境。UPD:
docker-compose.yml
version: "3.7"
services:
app:
build:
context: .
args:
JAR_FILE: build/libs/mdemo*-all.jar
ports:
- "8090:8090"
depends_on:
- db
environment:
SERVER_PORT: 8090
DB_HOST: db
db:
image: postgres:12
expose:
- "5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 1234
POSTGRES_DB: demo
最佳答案
我想您遇到了以下问题。
https://liquibase.jira.com/browse/CORE-3468
解决方法是
shadowJar {
manifest {
attributes 'Bundle-Version': 'UNKNOWN'
attributes 'Build-Time': 'UNKNOWN'
}
}
Micronaut仍在使用3.8.0版本的liquibasehttps://github.com/micronaut-projects/micronaut-liquibase/blob/master/gradle.properties#L8
库升级完成后,您将不再点击https://github.com/micronaut-projects/micronaut-liquibase/issues/74,但它将与Micronaut的2.1版一起发布。
关于java - Liquibase库在Micronaut 2.0中由于Nullpointer而失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63226983/