Skip to content

Sample log4j2 doesn't work with spring-boot >=2.0.0.RELEASE #59

@yejianfengblue

Description

@yejianfengblue

Reproduce steps:

  1. Start latest windows RabbitMQ on localhost:5672

  2. checkout master branch from this project spring-amqp-samples

  3. Go to module log4j2. You can see the spring-boot version should be 2.2.2.RELEASE in log4j2/pom.xml

  4. Run module log4j2. get error log from stdout

main ERROR Appenders contains an invalid element or attribute "RabbitMQ"
main ERROR Unable to locate appender "rabbitmq" for logger config "org.springframework.amqp.samples.log4j2"

  1. Delete exchange log4j2Sample from RabbitMQ management UI, because default value of durable in annotation org.springframework.amqp.rabbit.annotation.Exchange are different between different spring-rabbit version.

  2. Change spring-boot-starter-parent version in log4j2/pom.xml to 1.5.x.RELEASE (I tested 1.5.3, 1.5.10, 1.5.22), run module log4j2, sample works and you can see log

Log via AmqpAppender: Sun Jan 26 11:08:21 CST 2020
Logs over Log4J AmqpAppender: Log via AmqpAppender: Sun Jan 26 11:08:21 CST 2020

  1. Delete exchange log4j2Sample from RabbitMQ management UI, because default value of durable in annotation org.springframework.amqp.rabbit.annotation.Exchange are different between different spring-rabbit version.

  2. Change spring-boot-starter-parent version in log4j2/pom.xml to 2.0.0.RELEASE, run module log4j2, get error log

2020-01-26 11:10:31,034 main ERROR Unable to invoke factory method in class org.springframework.amqp.rabbit.log4j2.AmqpAppender for element RabbitMQ: java.lang.ExceptionInInitializerError 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.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:136)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.commons.logging.LogFactory$Log4jLog.(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.amqp.samples.log4j2.SpringBootAmqpAppenderApplication.(SpringBootAmqpAppenderApplication.java:43)
Caused by: java.lang.ExceptionInInitializerError
at org.springframework.expression.spel.SpelParserConfiguration.(SpelParserConfiguration.java:36)
at org.springframework.expression.spel.standard.SpelExpressionParser.(SpelExpressionParser.java:42)
at org.springframework.amqp.rabbit.core.RabbitTemplate.(RabbitTemplate.java:156)
at org.springframework.amqp.rabbit.log4j2.AmqpAppender.(AmqpAppender.java:120)
at org.springframework.amqp.rabbit.log4j2.AmqpAppender.createAppender(AmqpAppender.java:229)
... 23 more
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.LogFactory$Log4jLog.(LogFactory.java:204)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.core.SpringProperties.(SpringProperties.java:53)
... 28 more
2020-01-26 11:10:31,038 main ERROR Null object returned for RabbitMQ in Appenders.
2020-01-26 11:10:31,043 main ERROR Unable to locate appender "rabbitmq" for logger config "org.springframework.amqp.samples.log4j2"
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.run(Ljava/lang/Object;[Ljava/lang/String;)Lorg/springframework/context/ConfigurableApplicationContext;
at org.springframework.amqp.samples.log4j2.SpringBootAmqpAppenderApplication.main(SpringBootAmqpAppenderApplication.java:46)
Process finished with exit code 1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions