After you create a project based on the Spring Framework, the console prints a warning message when you use JUnit for unit testing:
Log4j:warn No Appenders could is found for logger (org.springframework.util.ClassUtils).
Log4j:warn Please initialize the log4j system properly.
Check on the Internet, incredibly many "suggestions" is to ignore these two warning messages, other search results are not satisfactory.
The workaround steps are as follows:
Name the log4j configuration file as log4j.properties. Add the Log4j.properties directory to the classpath. Add a Logger named Org.springframework to the log4j.properties. For example:
# Logger for Spring
Log4j.logger.org.springframework=debug, Org.springframework, stdout
Log4j.appender.org.springframework=org.apache.log4j.fileappender
Log4j.appender.org.springframework.file=/opt/adstat/log/spring.log
Log4j.appender.org.springframework.encoding=utf8
Log4j.appender.org.springframework.layout=org.apache.log4j.patternlayout
Log4j.appender.org.springframework.layout.conversionpattern=%-d{yyyy-mm-dd HH:MM:SS} [%c]-[%p]%m%n
After modification, the default settings required by Spring are met. Rerun the JUnit test, the above two warning messages are no longer displayed, and the corresponding Spring Framework information is exported to both the console and log files.