英文:
Liquibase library fails with Nullpointer in Micronaut 2.0
问题
I'll provide the translated content as requested:
我有一个Micronaut 2.0应用程序,带有micronaut-data(postgresql)和liquibase。
当我在IDEA或本地jar中运行应用程序时,它能正常工作。应用程序有几个迁移,并且当它在Docker中运行时,只有第一个迁移成功执行,然后出现以下错误:
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 | Caused by: java.lang.NullPointerException: null
app_1 | at liquibase.util.LiquibaseUtil.getBuildInfo(LiquibaseUtil.java:45)
...
第二次运行应用程序时出现错误:
relation marker_type already exists
如果将Micronaut降级到v1,并且不更改其他代码,然后在Docker中运行应用程序时没有问题。
在Micronaut 2中出了什么问题?
更新:
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 中的环境变量。
更新:
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
请注意,这里仅提供了翻译的代码部分,没有包含其他内容。
英文:
I have a Micronaut 2.0 app with micronaut-data (postgresql) and liquibase.
When I run app in IDEA or local jar, it works fine. App has several migrations and when it runs in docker only the first executes successfully, then it fails with error:
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
The second run of app has an error:
relation marker_type already exists
If downgrade Micronaut to v1 and don't change other code then app runs without problem in docker.
What's wrong in Micronaut 2?
UPD:
application.yml
's fragment:
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
is environment in 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
答案1
得分: 2
我猜你遇到了以下问题。
https://liquibase.jira.com/browse/CORE-3468
解决方法是
shadowJar {
manifest {
attributes 'Bundle-Version': 'UNKNOWN'
attributes 'Build-Time': 'UNKNOWN'
}
}
Micronaut仍然在使用liquibase的版本3.8.0
https://github.com/micronaut-projects/micronaut-liquibase/blob/master/gradle.properties#L8
在库升级完成后,你将不再遇到这个问题
https://github.com/micronaut-projects/micronaut-liquibase/issues/74 但它将在Micronaut的版本2.1中发布。
英文:
I guess you have hit following issue.
https://liquibase.jira.com/browse/CORE-3468
The workaround is
shadowJar {
manifest {
attributes 'Bundle-Version': 'UNKNOWN'
attributes 'Build-Time': 'UNKNOWN'
}
}
Micronaut is still using version 3.8.0 of liquibase
https://github.com/micronaut-projects/micronaut-liquibase/blob/master/gradle.properties#L8
After library upgrade is completed you will not hit it anymore https://github.com/micronaut-projects/micronaut-liquibase/issues/74 but it will be released with version 2.1 of Micronaut.
答案2
得分: 0
你可以分享你的resources文件夹中的application.properties或application.yaml吗?
我认为你的数据源没有配置,可能是通用的数据源或flyway中的一个。
我可以想象你在配置中依赖于环境变量,但你没有在容器启动时提供这些变量。
英文:
Could you share you application.properties or application.yaml in your resources folder?
I believe that your datasource isn't configured, could be the general one or the one in flyway.
I can imagine that you rely on env vars in that config but you didn't provided those on container startup.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论