Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.16.3: VersionPrinter fails initializing log4j logger when running the application natively #3659

Closed
ArnauAregall opened this issue Apr 23, 2023 · 5 comments

Comments

@ArnauAregall
Copy link

ArnauAregall commented Apr 23, 2023

Which version and edition of Flyway are you using?

flyway-core:9.16.3

If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Using the latest as of the time of opening the issue (23/04/23).

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Gradle plugin, Native

Which database are you using? (Type & version)

PostgreSQL latest (15.2)

Which operating system are you using?

macOS 13.3.1

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)
  • Create a Spring Boot application using 3.1.0-RC1 version
  • Add Flyway as a dependency
  • Run the application natively with ./gradlew nativeRun or either on a Docker image.
  • The Spring Boot application fails to start due org.flywaydb.core.internal.license.VersionPrinter not being able to get the logger.
docker-rest-api-1  | Caused by: java.lang.ExceptionInInitializerError: null
docker-rest-api-1  | 	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:61) ~[na:na]
docker-rest-api-1  | 	at org.flywaydb.core.internal.logging.log4j2.Log4j2LogCreator.createLogger(Log4j2LogCreator.java:24) ~[tech.aaregall.lab.movies.AppKt:na]
docker-rest-api-1  | 	at org.flywaydb.core.internal.logging.multi.MultiLogCreator.createLogger(MultiLogCreator.java:34) ~[na:na]
docker-rest-api-1  | 	at org.flywaydb.core.api.logging.LogFactory.getLog(LogFactory.java:89) ~[na:na]
docker-rest-api-1  | 	at org.flywaydb.core.internal.license.VersionPrinter.<clinit>(VersionPrinter.java:27) ~[na:na]
docker-rest-api-1  | 	at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:121) ~[na:na]
docker-rest-api-1  | 	at org.flywaydb.core.Flyway.migrate(Flyway.java:140) ~[tech.aaregall.lab.movies.AppKt:na]
docker-rest-api-1  | 	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[tech.aaregall.lab.movies.AppKt:3.1.0-RC1]
docker-rest-api-1  | 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1816) ~[tech.aaregall.lab.movies.AppKt:6.0.8]
docker-rest-api-1  | 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[tech.aaregall.lab.movies.AppKt:6.0.8]
docker-rest-api-1  | 	... 18 common frames omitted
docker-rest-api-1  | Caused by: java.lang.IllegalStateException: java.lang.InstantiationException: org.apache.logging.log4j.message.DefaultFlowMessageFactory
docker-rest-api-1  | 	at org.apache.logging.log4j.spi.AbstractLogger.createDefaultFlowMessageFactory(AbstractLogger.java:242) ~[tech.aaregall.lab.movies.AppKt:2.20.0]
docker-rest-api-1  | 	at org.apache.logging.log4j.spi.AbstractLogger.<init>(AbstractLogger.java:141) ~[tech.aaregall.lab.movies.AppKt:2.20.0]
docker-rest-api-1  | 	at org.apache.logging.log4j.status.StatusLogger.<init>(StatusLogger.java:141) ~[na:na]
docker-rest-api-1  | 	at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:91) ~[na:na]
docker-rest-api-1  | 	... 28 common frames omitted
docker-rest-api-1  | Caused by: java.lang.InstantiationException: org.apache.logging.log4j.message.DefaultFlowMessageFactory
docker-rest-api-1  | 	at java.base@17.0.6/java.lang.Class.newInstance(DynamicHub.java:639) ~[tech.aaregall.lab.movies.AppKt:na]
docker-rest-api-1  | 	at org.apache.logging.log4j.spi.AbstractLogger.createDefaultFlowMessageFactory(AbstractLogger.java:240) ~[tech.aaregall.lab.movies.AppKt:2.20.0]
docker-rest-api-1  | 	... 31 common frames omitted
docker-rest-api-1  | Caused by: java.lang.NoSuchMethodException: org.apache.logging.log4j.message.DefaultFlowMessageFactory.<init>()
docker-rest-api-1  | 	at java.base@17.0.6/java.lang.Class.getConstructor0(DynamicHub.java:3585) ~[tech.aaregall.lab.movies.AppKt:na]
docker-rest-api-1  | 	at java.base@17.0.6/java.lang.Class.newInstance(DynamicHub.java:626) ~[tech.aaregall.lab.movies.AppKt:na]
docker-rest-api-1  | 	... 32 common frames omitted
What did you expect to see?

Flyway printing the version correctly.

What did you see instead?

The mentioned stacktrace.

@wilkinsona
Copy link
Contributor

I think this issue has the same underlying cause as #3651.

@JasonLuo-Redgate
Copy link

Hi @ArnauAregall , just would like to confirm with you whether slf4j is the expected logger in your environment?

@ArnauAregall
Copy link
Author

ArnauAregall commented Jul 15, 2023

Hello @JasonLuo-Redgate, yes, it should.

By using Spring Boot starters I am not adding any specific logging dependency. Loggers are declared using slf4j.

import org.slf4j.Logger
import org.slf4j.LoggerFactory

public class App {
    public static final Logger = LoggerFactory.getLogger(App.class)
}

Here is the relevant part of the dependency tree in regards of logging in case it helps.

org.springframework.boot:spring-boot-starter:3.1.1-SNAPSHOT
    org.springframework.boot:spring-boot-starter-logging:3.1.1-SNAPSHOT
        ch.qos.logback:logback-classic:1.4.7
            ch.qos.logback:logback-core:1.4.7
            org.slf4j:slf4j-api:2.0.7
        org.apache.logging.log4j:log4j-to-slf4j:2.20.0
            org.apache.logging.log4j:log4j-api:2.20.0
            org.slf4j:slf4j-api:2.0.7
        org.slf4j:jul-to-slf4j:2.0.7
            org.slf4j:slf4j-api:2.0.7

@JasonLuo-Redgate
Copy link

Hi @ArnauAregall , thanks for your confirmation.
For now, there is a known bug that Flyway lost its ability to utilize slf4j.
It is likely that your issue is related to that bug, which explains why Flyway is still attempting to initialize log4j.
This bug is still under fixing.

@JasonLuo-Redgate
Copy link

This issue has been fixed in the latest version of Flyway, so closing this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants