Spring-boot和log4j生成stackoverflow异常

时间:2019-06-17 10:18:49

标签: java spring-boot log4j stack-overflow log4j2

我正在Spring Boot应用程序中使用Spring Boot版本2.1.5.RELEASE和log4j 2.11.2。如果启动我的应用程序,则会收到以下错误:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:593)
Caused by: java.lang.StackOverflowError
        at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
        at org.apache.logging.log4j.spi.LoggerRegistry.getOrCreateInnerMap(LoggerRegistry.java:140)
        at org.apache.logging.log4j.spi.LoggerRegistry.hasLogger(LoggerRegistry.java:154)

如果我排除 log4j-slf4j-impl ,则不会收到该错误,但不会使用我的 log4j2.xml 配置文件(无滚动文件)。但是,当我以Eclipse(调试模式)启动应用程序时,会使用 log4j2.xml , 但不能作为内置的jar文件。这是pom.xml的片段:

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
            </exclusions>
    </dependency>
    <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
    </dependency>

谁可以帮助我?

0 个答案:

没有答案